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

shift_start: {
        type: DataTypes.DATE,
      
      

      },

shift_end: {
        type: DataTypes.DATE,
      
      

      },

shift_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"superviseur",


"chef_cuisinier",


"cuisinier",


"caissier",


"barman",


"serveur",


"agent_entretien"

        ],

      },

shift_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planifie",


"confirme",


"annule"

        ],

      },

shift_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  work_shifts.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_shifts.hasMany(db.attendance_events, {
      as: 'attendance_events_work_shift',
      foreignKey: {
          name: 'work_shiftId',
      },
      constraints: false,
    });




















//end loop



    db.work_shifts.belongsTo(db.work_schedules, {
      as: 'work_schedule',
      foreignKey: {
        name: 'work_scheduleId',
      },
      constraints: false,
    });

    db.work_shifts.belongsTo(db.users, {
      as: 'staff_user',
      foreignKey: {
        name: 'staff_userId',
      },
      constraints: false,
    });




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

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



  return work_shifts;
};


