'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class TransactionItem 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) {
      TransactionItem.belongsTo(models.Transaction, {
        foreignKey: 'transactionId',
        as: 'transaction'
      });

      TransactionItem.belongsTo(models.Product, {
        foreignKey: 'productId',
        as: 'product'
      });

       TransactionItem.hasMany(models.ReturnItem, {
        foreignKey: 'transactionItemId',
        as: 'returs'
      });
    }
  }
  TransactionItem.init({
    transactionId: DataTypes.INTEGER,
    productId: DataTypes.INTEGER,
    productVariantId: DataTypes.INTEGER,
    quantity: DataTypes.DECIMAL,
    unitPrice: DataTypes.DECIMAL,
    discountAmount: DataTypes.DECIMAL,
    taxAmount: DataTypes.DECIMAL,
    totalAmount: DataTypes.DECIMAL,
    notes: DataTypes.TEXT
  }, {
    sequelize,
    modelName: 'TransactionItem',
  });
  return TransactionItem;
};