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

name: {
        type: DataTypes.TEXT,
      
      

      },

website: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

hq_location: {
        type: DataTypes.TEXT,
      
      

      },

last_updated_at: {
        type: DataTypes.DATE,
      
      

      },

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

  ir_companies.associate = (db) => {


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






























    db.ir_companies.hasMany(db.ir_management_members, {
      as: 'ir_management_members_ir_company',
      foreignKey: {
          name: 'ir_companyId',
      },
      constraints: false,
    });


    db.ir_companies.hasMany(db.ir_filings, {
      as: 'ir_filings_ir_company',
      foreignKey: {
          name: 'ir_companyId',
      },
      constraints: false,
    });


    db.ir_companies.hasMany(db.ir_dividends, {
      as: 'ir_dividends_ir_company',
      foreignKey: {
          name: 'ir_companyId',
      },
      constraints: false,
    });


    db.ir_companies.hasMany(db.ir_announcements, {
      as: 'ir_announcements_ir_company',
      foreignKey: {
          name: 'ir_companyId',
      },
      constraints: false,
    });


    db.ir_companies.hasMany(db.ir_financial_statement_summaries, {
      as: 'ir_financial_statement_summaries_ir_company',
      foreignKey: {
          name: 'ir_companyId',
      },
      constraints: false,
    });




//end loop



    db.ir_companies.belongsTo(db.market_symbols, {
      as: 'market_symbol',
      foreignKey: {
        name: 'market_symbolId',
      },
      constraints: false,
    });




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

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



  return ir_companies;
};


