'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    // Add tax_id column to material table
    await queryInterface.addColumn('material', 'tax_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'tax_master',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Reference to Tax Master for default tax rate'
    });

    // Add index for tax_id for better query performance
    await queryInterface.addIndex('material', ['tax_id'], {
      name: 'idx_material_tax_id'
    });
  },

  async down(queryInterface, Sequelize) {
    // Remove index first
    await queryInterface.removeIndex('material', 'idx_material_tax_id');
    
    // Remove tax_id column
    await queryInterface.removeColumn('material', 'tax_id');
  }
};

