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 ir_dividends = sequelize.define(
    'ir_dividends',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

declaration_at: {
        type: DataTypes.DATE,
      
      

      },

ex_dividend_at: {
        type: DataTypes.DATE,
      
      

      },

record_at: {
        type: DataTypes.DATE,
      
      

      },

payable_at: {
        type: DataTypes.DATE,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"USD",


"EUR",


"GBP",


"JPY"

        ],

      },

frequency: {
        type: DataTypes.ENUM,
      
      

        values: [

"one_time",


"quarterly",


"semi_annual",


"annual",


"monthly"

        ],

      },

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

  ir_dividends.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.ir_dividends.belongsTo(db.ir_companies, {
      as: 'ir_company',
      foreignKey: {
        name: 'ir_companyId',
      },
      constraints: false,
    });




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

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



  return ir_dividends;
};


