module.exports = (sequelize, DataTypes) => {
  const VendorPaymentItem = sequelize.define('VendorPaymentItem', {
    id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
    vendor_payment_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: { model: 'VendorPayment', key: 'id' }
    },
    line_no: { type: DataTypes.INTEGER, allowNull: false },
    payment_mode: {
      type: DataTypes.ENUM('CASH', 'BANK', 'UPI', 'CHEQUE', 'NEFT', 'ONLINE_TRANSFER'),
      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: 'vendor_payment_item',
    indexes: [{ fields: ['vendor_payment_id'] }, { fields: ['payment_mode'] }]
  });

  VendorPaymentItem.associate = function(models) {
    VendorPaymentItem.belongsTo(models.VendorPayment, { foreignKey: 'vendor_payment_id', as: 'vendorPayment' });
  };

  return VendorPaymentItem;
};
