import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Livestock is billed and counted per head, not per ton — line it up with the
 * other break-bulk cargo types (Machinery, Truck, Automobile) so bulk
 * storage/demurrage fees charge per item instead of per ton for it.
 */
export class LivestockPerItem2900000000000 implements MigrationInterface {
  name = "LivestockPerItem2900000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      UPDATE freight.cargo_types
         SET unit_of_measure = 'PER_ITEM'
       WHERE code = 'LIVESTOCK'
         AND unit_of_measure IS DISTINCT FROM 'PER_ITEM'
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      UPDATE freight.cargo_types
         SET unit_of_measure = 'PER_TON'
       WHERE code = 'LIVESTOCK'
         AND unit_of_measure IS DISTINCT FROM 'PER_TON'
    `);
  }
}
