/**
 * Migration: Seed Carriers and Test Organizations
 */

import { MigrationInterface, QueryRunner } from 'typeorm';
import { getCarriersInsertSQL } from '../seeds/carriers.seed';
import { getOrganizationsInsertSQL } from '../seeds/test-organizations.seed';

export class SeedCarriersAndOrganizations1730000000006 implements MigrationInterface {
  name = 'SeedCarriersAndOrganizations1730000000006';

  public async up(queryRunner: QueryRunner): Promise<void> {
    // Seed test organizations
    await queryRunner.query(getOrganizationsInsertSQL());

    // Seed carriers
    await queryRunner.query(getCarriersInsertSQL());
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    // Delete seeded data
    await queryRunner.query(
      `DELETE FROM "carriers" WHERE "code" IN ('MAERSK', 'MSC', 'CMA_CGM', 'HAPAG_LLOYD', 'ONE')`
    );
    await queryRunner.query(
      `DELETE FROM "organizations" WHERE "name" IN ('Test Freight Forwarder Inc.', 'Demo Shipping Company', 'Sample Shipper Ltd.')`
    );
  }
}
