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,
      },

base_currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"USD",


"CDF",


"EUR",


"GBP"

        ],

      },

quote_currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"USD",


"CDF",


"EUR",


"GBP"

        ],

      },

rate: {
        type: DataTypes.DECIMAL,
      
      

      },

effective_at: {
        type: DataTypes.DATE,
      
      

      },

      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.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.currency_rates.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return currency_rates;
};


