import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Per-row pickup / drop-off addresses on query_quote_transports —
 * mirrors the existing columns on booking_transport_items so a quote
 * can capture the exact locations agreed at sales-pitch time, then
 * carry them forward on convert-to-booking without forcing ops to
 * re-type. Makes addresses visible everywhere the row is rendered
 * (Quote builder, Booking editor, Movement Dashboard).
 *
 * varchar(500) matches the booking-side widths so a Google Places
 * result lands the same way in both tables. Both columns nullable
 * because existing rows pre-date this feature.
 */
export class QuoteTransportPickupDropoffAddress1781800000000 implements MigrationInterface {
  public async up(qr: QueryRunner): Promise<void> {
    await qr.query(
      `ALTER TABLE "query_quote_transports"
         ADD COLUMN IF NOT EXISTS "pickup_address" varchar(500) NULL,
         ADD COLUMN IF NOT EXISTS "dropoff_address" varchar(500) NULL`,
    );
  }

  public async down(qr: QueryRunner): Promise<void> {
    await qr.query(
      `ALTER TABLE "query_quote_transports"
         DROP COLUMN IF EXISTS "dropoff_address",
         DROP COLUMN IF EXISTS "pickup_address"`,
    );
  }
}
