const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const currency_rates = sequelize.define(
    'currency_rates',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

rate_date: {
        type: DataTypes.DATE,
      
      

      },

rate: {
        type: DataTypes.DECIMAL,
      
      

      },

source: {
        type: DataTypes.TEXT,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  currency_rates.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity

















































//end loop



    db.currency_rates.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });

    db.currency_rates.belongsTo(db.currencies, {
      as: 'from_currency',
      foreignKey: {
        name: 'from_currencyId',
      },
      constraints: false,
    });

    db.currency_rates.belongsTo(db.currencies, {
      as: 'to_currency',
      foreignKey: {
        name: 'to_currencyId',
      },
      constraints: false,
    });




    db.currency_rates.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.currency_rates.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return currency_rates;
};


