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

hold_number: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"released",


"expired"

        ],

      },

hold_started_at: {
        type: DataTypes.DATE,
      
      

      },

hold_released_at: {
        type: DataTypes.DATE,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.quality_holds.belongsTo(db.items, {
      as: 'item',
      foreignKey: {
        name: 'itemId',
      },
      constraints: false,
    });

    db.quality_holds.belongsTo(db.lots, {
      as: 'lot',
      foreignKey: {
        name: 'lotId',
      },
      constraints: false,
    });

    db.quality_holds.belongsTo(db.locations, {
      as: 'location',
      foreignKey: {
        name: 'locationId',
      },
      constraints: false,
    });

    db.quality_holds.belongsTo(db.users, {
      as: 'placed_by',
      foreignKey: {
        name: 'placed_byId',
      },
      constraints: false,
    });

    db.quality_holds.belongsTo(db.users, {
      as: 'released_by',
      foreignKey: {
        name: 'released_byId',
      },
      constraints: false,
    });




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

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



  return quality_holds;
};


