'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class ReturnItem 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
       // Association with Return
      ReturnItem.belongsTo(models.Return, {
        foreignKey: 'returnId',
        as: 'return'
      });
      
      // Association with TransactionItem
      ReturnItem.belongsTo(models.TransactionItem, {
        foreignKey: 'transactionItemId',
        as: 'transactionItem'
      });
      
      // Association with Product
      ReturnItem.belongsTo(models.Product, {
        foreignKey: 'productId',
        as: 'product'
      });
    }
  }
  ReturnItem.init({
    returnId: DataTypes.INTEGER,
    transactionItemId: DataTypes.INTEGER,
    productId: DataTypes.INTEGER,
    quantity: DataTypes.INTEGER,
    unitPrice: DataTypes.DECIMAL,
    subtotal: DataTypes.DECIMAL,
    taxAmount: DataTypes.DECIMAL,
    discountAmount: DataTypes.DECIMAL,
    totalAmount: DataTypes.DECIMAL,
    reason: DataTypes.TEXT,
    condition: DataTypes.STRING,
    isRestocked: DataTypes.BOOLEAN,
    restockedAt: DataTypes.DATE,
    notes: DataTypes.TEXT
  }, {
    sequelize,
    modelName: 'ReturnItem',
  });
  return ReturnItem;
};