import { type MigrationInterface, type QueryRunner } from 'typeorm';

/**
 * Adds `actual_supplier_cost` to `booking_activity_items` — the
 * activity-side equivalent of the same column on
 * `booking_transport_items`. Closes audit Gap #1 (activity items had
 * supplier_id but no cost basis to snapshot).
 *
 * Pattern mirrors transport exactly:
 *   - per-TRIP TOTAL semantic (qty already baked in at snapshot time)
 *   - populated at booking-create from the activity_pricing floor
 *     (analogous to resolveFloorSnapshot for transport)
 *   - overridable by ops on the Movement Chart Planner activity rows
 *     once supplier is assigned
 *   - drives the SUPPLIER REFUND amount on `recordSupplierPayable`
 *     when a supplier is first assigned
 *
 * Backfill is NOT attempted — existing rows with no supplier assigned
 * just stay NULL until ops touches them (no settlements at risk).
 */
export class ActivityActualSupplierCost1780600000000 implements MigrationInterface {
  async up(qr: QueryRunner): Promise<void> {
    await qr.query(`
      ALTER TABLE booking_activity_items
        ADD COLUMN IF NOT EXISTS actual_supplier_cost NUMERIC(12,2);
    `);
  }

  async down(qr: QueryRunner): Promise<void> {
    await qr.query(`
      ALTER TABLE booking_activity_items
        DROP COLUMN IF EXISTS actual_supplier_cost;
    `);
  }
}
