'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class StockMovement 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
      StockMovement.belongsTo(models.User, { foreignKey: 'performedBy', as: 'user' });
      StockMovement.belongsTo(models.Store, { foreignKey: 'storeId', as: 'store' });
      StockMovement.belongsTo(models.Product, { foreignKey: 'productId', as: 'product' });
    }
  }
  StockMovement.init({
    productId: DataTypes.INTEGER,
    productVariantId: DataTypes.INTEGER,
    storeId: DataTypes.INTEGER,
    movementType: DataTypes.STRING,
    quantity: DataTypes.INTEGER,
    referenceType: DataTypes.STRING,
    referenceId: DataTypes.INTEGER,
    notes: DataTypes.TEXT,
    performedBy: DataTypes.INTEGER,
    movementDate: DataTypes.DATE
  }, {
    sequelize,
    modelName: 'StockMovement',
  });
  return StockMovement;
};