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

job_title: {
        type: DataTypes.TEXT,
      
      

      },

employee_code: {
        type: DataTypes.TEXT,
      
      

      },

hire_date: {
        type: DataTypes.DATE,
      
      

      },

can_login: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  staff_profiles.associate = (db) => {


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









    db.staff_profiles.hasMany(db.shifts, {
      as: 'shifts_staff_profile',
      foreignKey: {
          name: 'staff_profileId',
      },
      constraints: false,
    });


















    db.staff_profiles.hasMany(db.housekeeping_tasks, {
      as: 'housekeeping_tasks_assigned_staff_profile',
      foreignKey: {
          name: 'assigned_staff_profileId',
      },
      constraints: false,
    });


    db.staff_profiles.hasMany(db.maintenance_tickets, {
      as: 'maintenance_tickets_assigned_staff_profile',
      foreignKey: {
          name: 'assigned_staff_profileId',
      },
      constraints: false,
    });








//end loop



    db.staff_profiles.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });

    db.staff_profiles.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.staff_profiles.belongsTo(db.departments, {
      as: 'department',
      foreignKey: {
        name: 'departmentId',
      },
      constraints: false,
    });

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




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

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



  return staff_profiles;
};


