'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('receipt_entry_item', {
      id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
      receipt_entry_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: { model: 'receipt_entry', key: 'id', onDelete: 'CASCADE' }
      },
      line_no: { type: Sequelize.INTEGER, allowNull: false },
      payment_mode: {
        type: Sequelize.ENUM('CASH', 'BANK', 'UPI', 'CHEQUE', 'NEFT'),
        allowNull: false
      },
      amount: { type: Sequelize.DECIMAL(18, 2), allowNull: false, defaultValue: 0 },
      bank_name: { type: Sequelize.STRING(120), allowNull: true },
      ifsc_code: { type: Sequelize.STRING(20), allowNull: true },
      reference_no: { type: Sequelize.STRING(120), allowNull: true },
      remarks: { type: Sequelize.TEXT, allowNull: true },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
      }
    });
    await queryInterface.addIndex('receipt_entry_item', ['receipt_entry_id']);
    await queryInterface.addIndex('receipt_entry_item', ['payment_mode']);
  },

  async down(queryInterface) {
    await queryInterface.dropTable('receipt_entry_item');
  }
};

