'use strict';

/**
 * Migration: Add suspendNote and isVoided columns to Transactions table
 */
module.exports = {
  up: async (queryInterface, Sequelize) => {
    // Get current table structure
    const transactionsTable = await queryInterface.describeTable('Transactions');

    // Add suspendNote column only if it doesn't exist
    if (!transactionsTable.suspendNote) {
      await queryInterface.addColumn('Transactions', 'suspendNote', {
        type: Sequelize.TEXT,
        allowNull: true
      });
    }

    // Add isVoided column only if it doesn't exist
    if (!transactionsTable.isVoided) {
      await queryInterface.addColumn('Transactions', 'isVoided', {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false
      });
    }
  },

  down: async (queryInterface, Sequelize) => {
    // Get current table structure
    const transactionsTable = await queryInterface.describeTable('Transactions');

    // Remove suspendNote column only if it exists
    if (transactionsTable.suspendNote) {
      await queryInterface.removeColumn('Transactions', 'suspendNote');
    }

    // Remove isVoided column only if it exists
    if (transactionsTable.isVoided) {
      await queryInterface.removeColumn('Transactions', 'isVoided');
    }
  }
};