'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('purchase_costing', 'status', {
      type: Sequelize.ENUM('NORMAL', 'WARNING', 'CRITICAL'),
      allowNull: false,
      defaultValue: 'NORMAL'
    });
    await queryInterface.addColumn('purchase_costing', 'reason', {
      type: Sequelize.STRING(300),
      allowNull: true
    });
    await queryInterface.addColumn('purchase_costing', 'approval_status', {
      type: Sequelize.ENUM('NOT_REQUIRED', 'PENDING', 'APPROVED', 'REJECTED'),
      allowNull: false,
      defaultValue: 'NOT_REQUIRED'
    });
    await queryInterface.addColumn('purchase_costing', 'created_date', {
      type: Sequelize.DATEONLY,
      allowNull: true
    });

    await queryInterface.addIndex('purchase_costing', ['status'], { name: 'purchase_costing_status_idx' });
    await queryInterface.addIndex('purchase_costing', ['approval_status'], { name: 'purchase_costing_approval_status_idx' });
  },

  async down(queryInterface) {
    await queryInterface.removeIndex('purchase_costing', 'purchase_costing_approval_status_idx');
    await queryInterface.removeIndex('purchase_costing', 'purchase_costing_status_idx');
    await queryInterface.removeColumn('purchase_costing', 'created_date');
    await queryInterface.removeColumn('purchase_costing', 'approval_status');
    await queryInterface.removeColumn('purchase_costing', 'reason');
    await queryInterface.removeColumn('purchase_costing', 'status');
  }
};
