module.exports = (sequelize, DataTypes) => {
  const ReceiptEntryItem = sequelize.define('ReceiptEntryItem', {
    id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
    receipt_entry_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: { model: 'ReceiptEntry', key: 'id' }
    },
    line_no: { type: DataTypes.INTEGER, allowNull: false },
    payment_mode: {
      type: DataTypes.ENUM('CASH', 'BANK', 'UPI', 'CHEQUE', 'NEFT'),
      allowNull: false
    },
    amount: { type: DataTypes.DECIMAL(18, 2), allowNull: false, defaultValue: 0 },
    bank_name: { type: DataTypes.STRING(120), allowNull: true },
    ifsc_code: { type: DataTypes.STRING(20), allowNull: true },
    reference_no: { type: DataTypes.STRING(120), allowNull: true },
    remarks: { type: DataTypes.TEXT, allowNull: true }
  }, {
    tableName: 'receipt_entry_item',
    indexes: [
      { fields: ['receipt_entry_id'] },
      { fields: ['payment_mode'] }
    ]
  });

  ReceiptEntryItem.associate = function(models) {
    ReceiptEntryItem.belongsTo(models.ReceiptEntry, { foreignKey: 'receipt_entry_id', as: 'receiptEntry' });
  };

  return ReceiptEntryItem;
};

