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

shift_name: {
        type: DataTypes.TEXT,
      
      

      },

shift_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"day",


"swing",


"night"

        ],

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"inactive"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  shifts.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.shifts.belongsTo(db.plants, {
      as: 'plant',
      foreignKey: {
        name: 'plantId',
      },
      constraints: false,
    });




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

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



  return shifts;
};


