import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * GENERAL contracts can be booked repeatedly until a total cargo quantity cap is
 * reached (e.g. 100 containers across many shipments). `quantity_cap` on each
 * cargo-scope line holds that ceiling (containers per size, or tons/items for
 * bulk). NULL = uncapped; always NULL for ONE_TIME (single booking).
 */
export class AddCargoScopeQuantityCap1826000000000 implements MigrationInterface {
  name = 'AddCargoScopeQuantityCap1826000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.contract_cargo_scope ADD COLUMN IF NOT EXISTS quantity_cap NUMERIC(12,2);`,
    );
  }

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