'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    // Add OPENING_BALANCE to transaction_type enum
    await queryInterface.sequelize.query(`
      ALTER TABLE inventory_stock_ledger 
      MODIFY COLUMN transaction_type ENUM(
        'RECEIPT', 
        'ISSUE', 
        'RETURN', 
        'SCRAP', 
        'ADJUSTMENT', 
        'TRANSFER_IN', 
        'TRANSFER_OUT',
        'OPENING_BALANCE'
      ) NOT NULL COMMENT 'Type of stock movement';
    `);

    // Add OPENING_BALANCE to reference_type enum
    await queryInterface.sequelize.query(`
      ALTER TABLE inventory_stock_ledger 
      MODIFY COLUMN reference_type ENUM(
        'GRN', 
        'MIN', 
        'MRN', 
        'SCRAP', 
        'ADJUSTMENT', 
        'TRANSFER', 
        'PRODUCTION_RECEIPT', 
        'OTHER',
        'OPENING_BALANCE'
      ) NOT NULL COMMENT 'Type of reference document';
    `);
  },

  async down(queryInterface, Sequelize) {
    // Remove OPENING_BALANCE from transaction_type enum
    await queryInterface.sequelize.query(`
      ALTER TABLE inventory_stock_ledger 
      MODIFY COLUMN transaction_type ENUM(
        'RECEIPT', 
        'ISSUE', 
        'RETURN', 
        'SCRAP', 
        'ADJUSTMENT', 
        'TRANSFER_IN', 
        'TRANSFER_OUT'
      ) NOT NULL COMMENT 'Type of stock movement';
    `);

    // Remove OPENING_BALANCE from reference_type enum
    await queryInterface.sequelize.query(`
      ALTER TABLE inventory_stock_ledger 
      MODIFY COLUMN reference_type ENUM(
        'GRN', 
        'MIN', 
        'MRN', 
        'SCRAP', 
        'ADJUSTMENT', 
        'TRANSFER', 
        'PRODUCTION_RECEIPT', 
        'OTHER'
      ) NOT NULL COMMENT 'Type of reference document';
    `);
  }
};

