import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Adds the transport cost breakdown (freight + FOB) to csv_bookings.
 *
 * These amounts are informational: they are paid to the carrier, not collected
 * by Xpeditis (which only charges the flat per-booking fee). Freight and FOB may
 * be quoted in different currencies, so each amount keeps its own currency.
 */
export class AddFreightFobToCsvBookings1740000000003 implements MigrationInterface {
  name = 'AddFreightFobToCsvBookings1740000000003';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE "csv_bookings"
      ADD COLUMN IF NOT EXISTS "freight_total" DECIMAL(12,2),
      ADD COLUMN IF NOT EXISTS "freight_currency" VARCHAR(3),
      ADD COLUMN IF NOT EXISTS "fob_total" DECIMAL(12,2),
      ADD COLUMN IF NOT EXISTS "fob_currency" VARCHAR(3)
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE "csv_bookings"
      DROP COLUMN IF EXISTS "fob_currency",
      DROP COLUMN IF EXISTS "fob_total",
      DROP COLUMN IF EXISTS "freight_currency",
      DROP COLUMN IF EXISTS "freight_total"
    `);
  }
}
