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

name: {
        type: DataTypes.TEXT,
      
      

      },

modality: {
        type: DataTypes.TEXT,
      
      

      },

body_region: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  procedure_families.associate = (db) => {


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











    db.procedure_families.hasMany(db.cpt_codes, {
      as: 'cpt_codes_procedure_family',
      foreignKey: {
          name: 'procedure_familyId',
      },
      constraints: false,
    });



    db.procedure_families.hasMany(db.authorization_cases, {
      as: 'authorization_cases_procedure_family',
      foreignKey: {
          name: 'procedure_familyId',
      },
      constraints: false,
    });









    db.procedure_families.hasMany(db.payer_rules, {
      as: 'payer_rules_procedure_family',
      foreignKey: {
          name: 'procedure_familyId',
      },
      constraints: false,
    });










//end loop



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




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

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



  return procedure_families;
};


