import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Add `has_lashing` to cargo types.
 *
 * When true, every booking of that cargo type incurs the flat LASHING
 * surcharge (a rate with trigger = 'LASHING'). Defaults to false so existing
 * cargo ships without the fee until the flag is turned on.
 */
export class AddCargoTypeHasLashing2340000000000 implements MigrationInterface {
  name = "AddCargoTypeHasLashing2340000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.cargo_types
        ADD COLUMN IF NOT EXISTS has_lashing boolean NOT NULL DEFAULT false;
    `);
  }

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