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

quantity_reserved: {
        type: DataTypes.DECIMAL,
      
      

      },

reserved_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"reserved",


"released",


"consumed"

        ],

      },

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

  stock_reservations.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.stock_reservations.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.stock_reservations.belongsTo(db.sales_orders, {
      as: 'sales_order',
      foreignKey: {
        name: 'sales_orderId',
      },
      constraints: false,
    });

    db.stock_reservations.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

    db.stock_reservations.belongsTo(db.warehouses, {
      as: 'warehouse',
      foreignKey: {
        name: 'warehouseId',
      },
      constraints: false,
    });




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

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



  return stock_reservations;
};


