'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // Check if columns exist before adding
    const tableDescription = await queryInterface.describeTable('customer_quotation_item');
    
    if (!tableDescription.cgst_rate) {
      await queryInterface.addColumn('customer_quotation_item', 'cgst_rate', {
        type: Sequelize.DECIMAL(5, 2),
        allowNull: false,
        defaultValue: 0
      });
    }
    
    if (!tableDescription.cgst_amount) {
      await queryInterface.addColumn('customer_quotation_item', 'cgst_amount', {
        type: Sequelize.DECIMAL(18, 2),
        allowNull: false,
        defaultValue: 0
      });
    }
    
    if (!tableDescription.sgst_rate) {
      await queryInterface.addColumn('customer_quotation_item', 'sgst_rate', {
        type: Sequelize.DECIMAL(5, 2),
        allowNull: false,
        defaultValue: 0
      });
    }
    
    if (!tableDescription.sgst_amount) {
      await queryInterface.addColumn('customer_quotation_item', 'sgst_amount', {
        type: Sequelize.DECIMAL(18, 2),
        allowNull: false,
        defaultValue: 0
      });
    }
    
    if (!tableDescription.igst_rate) {
      await queryInterface.addColumn('customer_quotation_item', 'igst_rate', {
        type: Sequelize.DECIMAL(5, 2),
        allowNull: false,
        defaultValue: 0
      });
    }
    
    if (!tableDescription.igst_amount) {
      await queryInterface.addColumn('customer_quotation_item', 'igst_amount', {
        type: Sequelize.DECIMAL(18, 2),
        allowNull: false,
        defaultValue: 0
      });
    }
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.removeColumn('customer_quotation_item', 'cgst_rate');
    await queryInterface.removeColumn('customer_quotation_item', 'cgst_amount');
    await queryInterface.removeColumn('customer_quotation_item', 'sgst_rate');
    await queryInterface.removeColumn('customer_quotation_item', 'sgst_amount');
    await queryInterface.removeColumn('customer_quotation_item', 'igst_rate');
    await queryInterface.removeColumn('customer_quotation_item', 'igst_amount');
  }
};

