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

filing_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"10k",


"10q",


"8k",


"s1",


"def14a",


"other"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

filed_at: {
        type: DataTypes.DATE,
      
      

      },

sec_url: {
        type: DataTypes.TEXT,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

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

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



    db.ir_filings.hasMany(db.file, {
      as: 'attachments',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.ir_filings.getTableName(),
        belongsToColumn: 'attachments',
      },
    });


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

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



  return ir_filings;
};


