'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('business_partner', 'vendor_category_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'vendor_category',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Reference to Vendor Category master (e.g., Regular Vendor, Sub Contractor, Job Worker)'
    });

    await queryInterface.addIndex('business_partner', {
      fields: ['vendor_category_id'],
      name: 'business_partner_vendor_category_id_idx'
    });
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.removeIndex('business_partner', 'business_partner_vendor_category_id_idx');
    await queryInterface.removeColumn('business_partner', 'vendor_category_id');
  }
};

