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

code: {
        type: DataTypes.TEXT,
      
      

      },

short_description: {
        type: DataTypes.TEXT,
      
      

      },

long_description: {
        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,
    },
  );

  cpt_codes.associate = (db) => {


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













    db.cpt_codes.hasMany(db.authorization_cases, {
      as: 'authorization_cases_cpt_code',
      foreignKey: {
          name: 'cpt_codeId',
      },
      constraints: false,
    });


















//end loop



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

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




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

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



  return cpt_codes;
};


