import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * `reference_type` was varchar(16) but `SUPPLEMENTARY_CHARGE` is 20 characters, causing
 * a value-too-long error whenever the passenger API initiates a supplementary-charge payment.
 * Widen to varchar(32) to accommodate all current and near-future PaymentReferenceType values.
 * Same fix applied to notification_outbox.reference_type for consistency.
 */
export class WideReferenceType1782100000000 implements MigrationInterface {
  name = "WideReferenceType1782100000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "edr_payment"."payment_intent" ALTER COLUMN "reference_type" TYPE varchar(32)`,
    );
    await queryRunner.query(
      `ALTER TABLE "edr_payment"."notification_outbox" ALTER COLUMN "reference_type" TYPE varchar(32)`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "edr_payment"."notification_outbox" ALTER COLUMN "reference_type" TYPE varchar(16)`,
    );
    await queryRunner.query(
      `ALTER TABLE "edr_payment"."payment_intent" ALTER COLUMN "reference_type" TYPE varchar(16)`,
    );
  }
}
