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

applicationDate: {
        type: DataTypes.DATE,
      
      

      },

firstName: {
        type: DataTypes.TEXT,
      
      

      },

lastName: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

mobile: {
        type: DataTypes.TEXT,
      
      

      },

source: {
        type: DataTypes.ENUM,
      
      

        values: [

"WALK_IN",


"REFERRAL",


"JOB_BOARD",


"INTERNAL"

        ],

      },

interviewSchedule: {
        type: DataTypes.DATE,
      
      

      },

interviewResult: {
        type: DataTypes.ENUM,
      
      

        values: [

"PASS",


"FAIL",


"SECOND_INTERVIEW",


"PENDING"

        ],

      },

psychTestResult: {
        type: DataTypes.TEXT,
      
      

      },

medicalResult: {
        type: DataTypes.TEXT,
      
      

      },

backgroundCheck: {
        type: DataTypes.TEXT,
      
      

      },

jobOfferStatus: {
        type: DataTypes.ENUM,
      
      

        values: [

"PENDING",


"ACCEPTED",


"DECLINED"

        ],

      },

expectedStartDate: {
        type: DataTypes.DATE,
      
      

      },

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

  applicants.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.applicants.belongsTo(db.job_requisitions, {
      as: 'jobRequisition',
      foreignKey: {
        name: 'jobRequisitionId',
      },
      constraints: false,
    });

    db.applicants.belongsTo(db.employees, {
      as: 'convertedEmployee',
      foreignKey: {
        name: 'convertedEmployeeId',
      },
      constraints: false,
    });



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


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

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



  return applicants;
};


