import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Widen train_scheduling_global_rules.window_duration_hours from numeric(4,2)
 * to numeric(6,4). The UI now lets staff enter the booking-window duration in
 * minutes / hours / days and converts to the column's native hours unit; a
 * 4-minute window is 0.0667h, which numeric(4,2) rounds to 0.07 (≈3.96 min).
 * Four decimals store sub-minute durations exactly (0.0667h → 4.00 min).
 */
export class WidenWindowDurationHoursPrecision1910000000000
  implements MigrationInterface
{
  name = "WidenWindowDurationHoursPrecision1910000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.train_scheduling_global_rules
        ALTER COLUMN window_duration_hours TYPE numeric(6, 4);
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.train_scheduling_global_rules
        ALTER COLUMN window_duration_hours TYPE numeric(4, 2);
    `);
  }
}
