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

provider_name: {
        type: DataTypes.TEXT,
      
      

      },

policy_number: {
        type: DataTypes.TEXT,
      
      

      },

group_number: {
        type: DataTypes.TEXT,
      
      

      },

coverage_type: {
        type: DataTypes.TEXT,
      
      

      },

contact_phone: {
        type: DataTypes.TEXT,
      
      

      },

claims_contact: {
        type: DataTypes.TEXT,
      
      

      },

preauthorisation_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  insurance_policies.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.insurance_policies.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



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


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

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



  return insurance_policies;
};


