'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class StockAdjustment extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
      StockAdjustment.belongsTo(models.User, { as: 'adjustedByUser', foreignKey: 'adjustedBy' });
      StockAdjustment.belongsTo(models.User, { as: 'approvedByUser', foreignKey: 'approvedBy' });
      StockAdjustment.belongsTo(models.Product, { foreignKey: 'productId' });
      // StockAdjustment.belongsTo(models.Variant, { foreignKey: 'variantId' });
      // StockAdjustment.belongsTo(models.Warehouse, { foreignKey: 'warehouseId' });
    }
  }
  StockAdjustment.init({
    productId: DataTypes.INTEGER,
    variantId: DataTypes.INTEGER,
    warehouseId: DataTypes.INTEGER,
    adjustmentType: DataTypes.STRING,
    quantityBefore: DataTypes.INTEGER,
    quantityAdjusted: DataTypes.INTEGER,
    quantityAfter: DataTypes.INTEGER,
    reason: DataTypes.STRING,
    referenceType: DataTypes.STRING,
    referenceId: DataTypes.INTEGER,
    cost: DataTypes.DECIMAL,
    totalValue: DataTypes.DECIMAL,
    adjustedBy: DataTypes.INTEGER,
    approvedBy: DataTypes.INTEGER,
    adjustmentDate: DataTypes.DATE,
    notes: DataTypes.TEXT,
    batchNumber: DataTypes.STRING,
    expiryDate: DataTypes.DATE,
    status: DataTypes.STRING
  }, {
    sequelize,
    modelName: 'StockAdjustment',
  });
  return StockAdjustment;
};