import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Disposal service support — adds two optional columns to
 * transport_services so a single service row can represent an
 * "at-disposal" package (Half day / Full day 8h-12h / Hourly) instead
 * of a point-to-point route.
 *
 * Schema rationale:
 *   - duty_type carries the operational shape (HALF_DAY_4H,
 *     FULL_DAY_8H, FULL_DAY_10H, FULL_DAY_12H, HOURLY). NULL for
 *     existing pickup/drop/one-way/two-way rows.
 *   - duration_hours stores the displayed window length so the UI can
 *     show "10:00 → 20:00" without re-deriving from the enum. For
 *     fixed-duty values it mirrors the enum (8/10/12/4); for HOURLY it
 *     captures the ops-typed custom duration.
 *
 * Reuses the existing transport_pricing matrix unchanged — disposal
 * services are just new rows in the master, so the per-vehicle-type
 * pricing scaffold auto-fills via TransportServiceService.syncPricingMatrix
 * on create. No new pricing table.
 */
export class TransportDisposalService1781700000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "transport_services" ADD COLUMN IF NOT EXISTS "duty_type" varchar(20) NULL`,
    );
    await queryRunner.query(
      `ALTER TABLE "transport_services" ADD COLUMN IF NOT EXISTS "duration_hours" numeric(4, 1) NULL`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "transport_services" DROP COLUMN IF EXISTS "duration_hours"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transport_services" DROP COLUMN IF EXISTS "duty_type"`,
    );
  }
}
