import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Import self-haul trucks are weighed on leaving. The customer does not
 * pre-specify what an import truck takes — staff register the containers loaded
 * and the weighed gross when the truck departs. These columns capture that.
 */
export class AddCustomerTruckDeparture1970000000000 implements MigrationInterface {
  name = 'AddCustomerTruckDeparture1970000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.customer_truck_assignments
        ADD COLUMN IF NOT EXISTS gross_weight_kg numeric(14, 2),
        ADD COLUMN IF NOT EXISTS departed_at timestamptz
    `);
  }

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