import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Adds locomotives.overage_tolerance_tons / overage_tolerance_meters: an
 * optional per-locomotive deviation allowance above max_pull_weight_tons /
 * max_train_length_meters. Nullable, defaults to no tolerance so existing
 * strict-cap behavior is unchanged until staff sets a value.
 */
export class AddLocomotiveOverageTolerance2040000000000
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.locomotives
        ADD COLUMN IF NOT EXISTS overage_tolerance_tons NUMERIC(10, 3),
        ADD COLUMN IF NOT EXISTS overage_tolerance_meters NUMERIC(10, 3);
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.locomotives
        DROP COLUMN IF EXISTS overage_tolerance_tons,
        DROP COLUMN IF EXISTS overage_tolerance_meters;
    `);
  }
}
