import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddEnumOtpActionTypeAndUpdateColumnOtpVerifier1750045520332
  implements MigrationInterface
{
  name = 'AddEnumOtpActionTypeAndUpdateColumnOtpVerifier1750045520332';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "otp_verifier" ADD "is_all_action" boolean NOT NULL DEFAULT false`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."otp_verifier_action_types_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION', 'ACTIVATE_ITEM', 'ACTIVATE_USER', 'UPDATE_ITEM_PRICE', 'UPDATE_ITEM_DETAILS', 'CONFIRM_TRANSACTION')`,
    );
    await queryRunner.query(
      `ALTER TABLE "otp_verifier" ADD "action_types" "public"."otp_verifier_action_types_enum" array`,
    );
    await queryRunner.query(
      `ALTER TYPE "public"."otp_verifications_action_type_enum" RENAME TO "otp_verifications_action_type_enum_old"`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."otp_verifications_action_type_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION', 'ACTIVATE_ITEM', 'ACTIVATE_USER', 'UPDATE_ITEM_PRICE', 'UPDATE_ITEM_DETAILS', 'CONFIRM_TRANSACTION')`,
    );
    await queryRunner.query(
      `ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum"`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."otp_verifications_action_type_enum_old"`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TYPE "public"."otp_verifications_action_type_enum_old" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION')`,
    );
    await queryRunner.query(
      `ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum_old" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum_old"`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."otp_verifications_action_type_enum"`,
    );
    await queryRunner.query(
      `ALTER TYPE "public"."otp_verifications_action_type_enum_old" RENAME TO "otp_verifications_action_type_enum"`,
    );
    await queryRunner.query(
      `ALTER TABLE "otp_verifier" DROP COLUMN "action_types"`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."otp_verifier_action_types_enum"`,
    );
    await queryRunner.query(
      `ALTER TABLE "otp_verifier" DROP COLUMN "is_all_action"`,
    );
  }
}
