-- 025_crtc_pipeline_tracking.sql
-- Add columns to track each pipeline step's completion for CRTC orders.

BEGIN;

-- Domain + email provisioning
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS ca_domain TEXT;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS domain_provisioned_at TIMESTAMPTZ;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS domain_credentials_sent_at TIMESTAMPTZ;

-- Canadian DID
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS ca_did_number TEXT;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS did_provisioned_at TIMESTAMPTZ;

-- CRTC registration submission
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS crtc_submitted_at TIMESTAMPTZ;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS crtc_submitted_from_email TEXT;

-- BITS affidavit + notarization + submission
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS bits_affidavit_minio_path TEXT;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS bits_notary_order_id TEXT;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS bits_notarized_at TIMESTAMPTZ;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS bits_notarized_minio_path TEXT;
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS bits_submitted_at TIMESTAMPTZ;

-- CCTS registration
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS ccts_registered_at TIMESTAMPTZ;

-- Banking referral
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS banking_referral_sent_at TIMESTAMPTZ;

-- Order confirmation email
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS confirmation_email_sent_at TIMESTAMPTZ;

-- ERPNext Sales Order link (webhooks fire on Sales Order state changes)
ALTER TABLE canada_crtc_orders ADD COLUMN IF NOT EXISTS erpnext_sales_order TEXT;

COMMIT;
