import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Adds bookings.consolidation_resume_status: the status a booking parked in
 * PENDING_CONSOLIDATION returns to once it pairs with a wagon partner.
 *
 * Direct customer bookings leave it NULL (they resume to SUBMITTED, unchanged).
 * Contract-drawdown bookings (GL shipments) set it to the status
 * createUnderContract would otherwise have used (OPERATION_REQUEST_PENDING or
 * AWAITING_DOCUMENTS), so pairing resumes them into the contract-booking flow
 * instead of wrongly moving them to SUBMITTED.
 */
export class AddConsolidationResumeStatus2010000000000
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.bookings
        ADD COLUMN IF NOT EXISTS consolidation_resume_status VARCHAR(40);
    `);
  }

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