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

level: {
        type: DataTypes.ENUM,
      
      

        values: [

"sp1",


"sp2",


"sp3"

        ],

      },

issued_at: {
        type: DataTypes.DATE,
      
      

      },

valid_until: {
        type: DataTypes.DATE,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"closed",


"cancelled"

        ],

      },

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

  disciplinary_actions.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.disciplinary_actions.belongsTo(db.employees, {
      as: 'employee',
      foreignKey: {
        name: 'employeeId',
      },
      constraints: false,
    });

    db.disciplinary_actions.belongsTo(db.outlets, {
      as: 'outlet',
      foreignKey: {
        name: 'outletId',
      },
      constraints: false,
    });

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



    db.disciplinary_actions.hasMany(db.file, {
      as: 'evidence_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.disciplinary_actions.getTableName(),
        belongsToColumn: 'evidence_files',
      },
    });


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

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



  return disciplinary_actions;
};


