'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const table = 'route_card_operation';
    const cols = await queryInterface.describeTable(table);

    if (!cols.fr_rejected_qty) {
      await queryInterface.addColumn(table, 'fr_rejected_qty', {
        type: Sequelize.DECIMAL(18, 3),
        allowNull: false,
        defaultValue: 0,
        after: 'rejected_qty',
      });
    }
    if (!cols.mr_rejected_qty) {
      await queryInterface.addColumn(table, 'mr_rejected_qty', {
        type: Sequelize.DECIMAL(18, 3),
        allowNull: false,
        defaultValue: 0,
        after: 'fr_rejected_qty',
      });
    }
    if (!cols.rejection_fr) {
      await queryInterface.addColumn(table, 'rejection_fr', {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        after: 'mr_rejected_qty',
      });
    }
    if (!cols.rejection_mr) {
      await queryInterface.addColumn(table, 'rejection_mr', {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        after: 'rejection_fr',
      });
    }
  },

  async down(queryInterface) {
    const table = 'route_card_operation';
    const cols = await queryInterface.describeTable(table);

    if (cols.rejection_mr) {
      await queryInterface.removeColumn(table, 'rejection_mr');
    }
    if (cols.rejection_fr) {
      await queryInterface.removeColumn(table, 'rejection_fr');
    }
    if (cols.mr_rejected_qty) {
      await queryInterface.removeColumn(table, 'mr_rejected_qty');
    }
    if (cols.fr_rejected_qty) {
      await queryInterface.removeColumn(table, 'fr_rejected_qty');
    }
  },
};
