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

documentType: {
        type: DataTypes.ENUM,
      
      

        values: [

"NBI_CLEARANCE",


"MEDICAL_CERTIFICATE",


"SSS_FORM",


"PHILHEALTH_MDR",


"PAGIBIG_MMID",


"BIR_FORM",


"EMPLOYMENT_CONTRACT",


"JOB_OFFER",


"DIPLOMA",


"TRAINING_CERTIFICATE",


"PERFORMANCE_APPRAISAL",


"CONSENT_FORM",


"OTHER"

        ],

      },

fileName: {
        type: DataTypes.TEXT,
      
      

      },

uploadedAt: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.employee_documents.belongsTo(db.users, {
      as: 'uploadedByUser',
      foreignKey: {
        name: 'uploadedByUserId',
      },
      constraints: false,
    });



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


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

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



  return employee_documents;
};


