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

/**
 * Floor pricing — lowest sellable price per (route × vehicle × season).
 * Mirrors the existing default_price + season_1..5_price matrix so the
 * Transport Pricing editor can render selling and floor side-by-side
 * (one row each), and quote/booking saves can validate `unit_price`
 * against the same season's floor.
 *
 * All columns nullable — null means "no floor configured for this
 * season, allow any price". A tenant-level strict-by-default toggle
 * may follow in Phase 2 if stakeholders ask for it.
 */
export class TransportFloorPrice1777200000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE transport_pricing ADD COLUMN IF NOT EXISTS floor_default_price  NUMERIC(12,2)`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing ADD COLUMN IF NOT EXISTS floor_season_1_price NUMERIC(12,2)`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing ADD COLUMN IF NOT EXISTS floor_season_2_price NUMERIC(12,2)`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing ADD COLUMN IF NOT EXISTS floor_season_3_price NUMERIC(12,2)`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing ADD COLUMN IF NOT EXISTS floor_season_4_price NUMERIC(12,2)`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing ADD COLUMN IF NOT EXISTS floor_season_5_price NUMERIC(12,2)`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE transport_pricing DROP COLUMN IF EXISTS floor_season_5_price`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing DROP COLUMN IF EXISTS floor_season_4_price`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing DROP COLUMN IF EXISTS floor_season_3_price`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing DROP COLUMN IF EXISTS floor_season_2_price`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing DROP COLUMN IF EXISTS floor_season_1_price`,
    );
    await queryRunner.query(
      `ALTER TABLE transport_pricing DROP COLUMN IF EXISTS floor_default_price`,
    );
  }
}
