import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Currency moved from the contract to the shipment: a contract now quotes in
 * USD and the customer picks the billing currency per booking. On a customs
 * contract GL books on the customer's behalf, so the shipment request is where
 * the customer states the currency — GL reads it when creating the booking.
 *
 * Nullable: requests submitted before this change fall back to the contract's
 * own currency, which is exactly what their bookings already used.
 */
export class AddBookingRequestCurrency2980000000000 implements MigrationInterface {
  name = 'AddBookingRequestCurrency2980000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.booking_requests ADD COLUMN IF NOT EXISTS payment_currency varchar(5);`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.booking_requests DROP COLUMN IF EXISTS payment_currency;`,
    );
  }
}
