import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Add a hard per-unit weight ceiling to weight limit rules.
 *
 * maxVgmTons stays the soft "overweight" threshold (surcharge + warning);
 * max_capacity_tons is the absolute ceiling above which a booking cannot be
 * created at all. Null means no ceiling (existing behavior).
 */
export class AddMaxCapacityToWeightLimitRules1930000000000
  implements MigrationInterface
{
  name = "AddMaxCapacityToWeightLimitRules1930000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.weight_limit_rules
        ADD COLUMN IF NOT EXISTS max_capacity_tons numeric(8, 3);
    `);
  }

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