'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const table = 'production_final_inspection';
    const tables = await queryInterface.showAllTables();
    if (!tables.includes(table)) return;

    const dialect = queryInterface.sequelize.getDialect();
    if (dialect === 'mysql' || dialect === 'mariadb') {
      await queryInterface.sequelize.query(
        "ALTER TABLE `production_final_inspection` MODIFY `status` ENUM('PENDING','IN_PROGRESS','COMPLETED','APPROVED') NOT NULL DEFAULT 'PENDING';"
      );
      return;
    }

    await queryInterface.changeColumn(table, 'status', {
      type: Sequelize.ENUM('PENDING', 'IN_PROGRESS', 'COMPLETED', 'APPROVED'),
      allowNull: false,
      defaultValue: 'PENDING'
    });
  },

  async down(queryInterface, Sequelize) {
    const table = 'production_final_inspection';
    const tables = await queryInterface.showAllTables();
    if (!tables.includes(table)) return;

    const dialect = queryInterface.sequelize.getDialect();
    if (dialect === 'mysql' || dialect === 'mariadb') {
      await queryInterface.sequelize.query(
        "ALTER TABLE `production_final_inspection` MODIFY `status` ENUM('PENDING','IN_PROGRESS','COMPLETED') NOT NULL DEFAULT 'PENDING';"
      );
      return;
    }

    await queryInterface.changeColumn(table, 'status', {
      type: Sequelize.ENUM('PENDING', 'IN_PROGRESS', 'COMPLETED'),
      allowNull: false,
      defaultValue: 'PENDING'
    });
  }
};
