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

contract_number: {
        type: DataTypes.TEXT,
      
      

      },

start_date: {
        type: DataTypes.DATE,
      
      

      },

end_date: {
        type: DataTypes.DATE,
      
      

      },

contract_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"permanent",


"fixed_term",


"probation",


"consultant"

        ],

      },

base_salary: {
        type: DataTypes.DECIMAL,
      
      

      },

salary_period: {
        type: DataTypes.ENUM,
      
      

        values: [

"monthly",


"daily",


"hourly"

        ],

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"active",


"expired",


"terminated"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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



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


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

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



  return employment_contracts;
};


