import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * A facility handles what its equipment can handle. Containers need a reach
 * stacker or gantry, so only Indode, Modjo and Dire Dawa take them; bulk needs
 * far less, so all five facilities load and unload it.
 *
 * Both default true — a facility handles everything unless someone says
 * otherwise, which keeps existing rows working and makes the seeder the place
 * where the real capability is stated.
 */
export class YardFacilityFreightTypes2320000000000 implements MigrationInterface {
  name = 'YardFacilityFreightTypes2320000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.yard_facilities
        ADD COLUMN IF NOT EXISTS handles_container boolean NOT NULL DEFAULT true,
        ADD COLUMN IF NOT EXISTS handles_bulk      boolean NOT NULL DEFAULT true
    `);
  }

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