import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Add paid column to first_mile and last_mile tables to track invoice payment status.
 */
export class AddPaidToFirstAndLastMile1860000000000
  implements MigrationInterface
{
  name = "AddPaidToFirstAndLastMile1860000000000";

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

    await queryRunner.query(`
      ALTER TABLE freight.last_mile
        ADD COLUMN IF NOT EXISTS paid boolean NOT NULL DEFAULT false;
    `);
  }

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

    await queryRunner.query(`
      ALTER TABLE freight.last_mile
        DROP COLUMN IF EXISTS paid;
    `);
  }
}
