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

contract_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"probation",


"contract",


"permanent"

        ],

      },

start_date: {
        type: DataTypes.DATE,
      
      

      },

end_date: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"active",


"ended",


"cancelled"

        ],

      },

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

  employee_contracts.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.employee_contracts.belongsTo(db.employees, {
      as: 'employee',
      foreignKey: {
        name: 'employeeId',
      },
      constraints: false,
    });

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



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


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

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



  return employee_contracts;
};


