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

name: {
        type: DataTypes.TEXT,
      
      

      },

plan_code: {
        type: DataTypes.TEXT,
      
      

      },

network_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"hmo",


"ppo",


"epo",


"pos",


"medicare_advantage",


"other"

        ],

      },

active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  payer_plans.associate = (db) => {


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













    db.payer_plans.hasMany(db.authorization_cases, {
      as: 'authorization_cases_payer_plan',
      foreignKey: {
          name: 'payer_planId',
      },
      constraints: false,
    });









    db.payer_plans.hasMany(db.payer_rules, {
      as: 'payer_rules_payer_plan',
      foreignKey: {
          name: 'payer_planId',
      },
      constraints: false,
    });










//end loop



    db.payer_plans.belongsTo(db.payers, {
      as: 'payer',
      foreignKey: {
        name: 'payerId',
      },
      constraints: false,
    });

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




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

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



  return payer_plans;
};


