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

quantity_on_hand: {
        type: DataTypes.INTEGER,
      
      

      },

received_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

unit_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

quality_grade: {
        type: DataTypes.ENUM,
      
      

        values: [

"standard",


"fresh",


"premium",


"damaged"

        ],

      },

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

  store_inventory_batches.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.store_inventory_batches.belongsTo(db.store_products, {
      as: 'store_product',
      foreignKey: {
        name: 'store_productId',
      },
      constraints: false,
    });




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

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



  return store_inventory_batches;
};


