import { type MigrationInterface, type QueryRunner } from 'typeorm';

/**
 * Flips the column-level default of `tax_inclusive` from FALSE to TRUE
 * on both `query_quotes` and `bookings` (client feedback 2026-05-13).
 *
 * Why a default-only change (not a data backfill):
 *   - The client confirmed existing rows are mock/test data and should
 *     keep whatever flag they currently have. A backfill would alter
 *     historical totals and risk breaking the math on legacy quotes.
 *   - Only new rows created after this migration runs pick up the new
 *     default — that aligns with the new business rule (all prices
 *     are tax-inclusive by default going forward).
 *
 * Idempotent: ALTER COLUMN SET DEFAULT is safe to re-run.
 *
 * Paired entity changes:
 *   - `query-quote.entity.ts`: @Column default: true
 *   - `booking.entity.ts`:     @Column default: true
 */
export class DefaultTaxInclusiveTrue1778300000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE query_quotes ALTER COLUMN tax_inclusive SET DEFAULT true`);
    await queryRunner.query(`ALTER TABLE bookings    ALTER COLUMN tax_inclusive SET DEFAULT true`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE query_quotes ALTER COLUMN tax_inclusive SET DEFAULT false`,
    );
    await queryRunner.query(`ALTER TABLE bookings    ALTER COLUMN tax_inclusive SET DEFAULT false`);
  }
}
