import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Drop the unused reopen-delay knob from the global rules.
 *
 * The window engine never honoured `reopen_delay_minutes`: a not-yet-full train
 * reopens as soon as its payment phase settles, so the real gap between a cycle
 * closing and reopening is doc review + payment — nothing else. The per-schedule
 * `rule_reopen_delay_minutes` snapshot stays: it freezes that derived gap at
 * creation so the batch board keeps projecting the cycles the customer was shown.
 */
export class DropReopenDelayMinutes2190000000000 implements MigrationInterface {
  name = "DropReopenDelayMinutes2190000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.train_scheduling_global_rules
        DROP COLUMN IF EXISTS reopen_delay_minutes;
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.train_scheduling_global_rules
        ADD COLUMN IF NOT EXISTS reopen_delay_minutes integer NOT NULL DEFAULT 90;
    `);
  }
}
