import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Adds freight.booking_container.return_quantity — how many units of a
 * container line ship with the empty-container-return service (≤ quantity).
 * Mirrors hazardous_quantity / reefer_quantity: captured per line at booking
 * creation when the contract enables WITH_RETURN (container freight only) and
 * drives the booking-level equipment_return flag that fires the WITH_RETURN
 * pricing surcharge.
 */
export class AddContainerReturnQuantity2270000000000
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.booking_container
        ADD COLUMN IF NOT EXISTS return_quantity SMALLINT NOT NULL DEFAULT 0;
    `);
  }

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