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,
      },

title: {
        type: DataTypes.TEXT,
      
      

      },

period_start: {
        type: DataTypes.DATE,
      
      

      },

period_end: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"brouillon",


"publie",


"archive"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

      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.work_shifts, {
      as: 'work_shifts_work_schedule',
      foreignKey: {
          name: 'work_scheduleId',
      },
      constraints: false,
    });





















//end loop



    db.work_schedules.belongsTo(db.restaurants, {
      as: 'restaurant',
      foreignKey: {
        name: 'restaurantId',
      },
      constraints: false,
    });

    db.work_schedules.belongsTo(db.users, {
      as: 'created_by_user',
      foreignKey: {
        name: 'created_by_userId',
      },
      constraints: false,
    });




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

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



  return work_schedules;
};


