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

name: {
        type: DataTypes.TEXT,
      
      

      },

schedule_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"fixed",


"flexible",


"shift"

        ],

      },

work_minutes_per_day: {
        type: DataTypes.INTEGER,
      
      

      },

break_minutes_per_day: {
        type: DataTypes.INTEGER,
      
      

      },

effective_from: {
        type: DataTypes.DATE,
      
      

      },

effective_to: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"inactive"

        ],

      },

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

  work_schedules.associate = (db) => {


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


















    db.work_schedules.hasMany(db.employee_schedule_assignments, {
      as: 'employee_schedule_assignments_work_schedule',
      foreignKey: {
          name: 'work_scheduleId',
      },
      constraints: false,
    });











//end loop



    db.work_schedules.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

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




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

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



  return work_schedules;
};


