import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Adds per-service WhatsApp body fields to the Activity + Transport
 * Service masters.
 *
 * Stakeholder direction 2026-07-01: rather than storing per-activity
 * WhatsApp copy inside the Communication Templates master (which
 * would grow one row per activity per tenant), keep the templates
 * as thin wrappers with a single {{service_body}} token, and hold
 * the activity-/transport-specific copy directly on the master. Two
 * fields per master — one for the guest-facing (customer) message,
 * one for the supplier-facing message — because the two audiences
 * usually need very different content (inclusions/highlights for
 * the guest; job-specific handling notes for the supplier).
 *
 * Both fields are nullable text so freshly-created masters render
 * their wrapper template with an empty middle section (the wrapper
 * uses {{#if service_body}}…{{/if}} so it collapses gracefully).
 */
export class ServiceWhatsAppBodyFields1783100000000 implements MigrationInterface {
  name = 'ServiceWhatsAppBodyFields1783100000000';

  public async up(qr: QueryRunner): Promise<void> {
    await qr.query(`
      ALTER TABLE activities
        ADD COLUMN customer_whatsapp_body text,
        ADD COLUMN supplier_whatsapp_body text;
    `);
    await qr.query(`
      ALTER TABLE transport_services
        ADD COLUMN customer_whatsapp_body text,
        ADD COLUMN supplier_whatsapp_body text;
    `);
  }

  public async down(qr: QueryRunner): Promise<void> {
    await qr.query(`
      ALTER TABLE transport_services
        DROP COLUMN IF EXISTS supplier_whatsapp_body,
        DROP COLUMN IF EXISTS customer_whatsapp_body;
    `);
    await qr.query(`
      ALTER TABLE activities
        DROP COLUMN IF EXISTS supplier_whatsapp_body,
        DROP COLUMN IF EXISTS customer_whatsapp_body;
    `);
  }
}
