-- Migration 020: Agency tier  -  sub-account structure + white-label config
-- Applied: 2026-05-21
-- Idempotent: uses IF NOT EXISTS / INSERT IGNORE throughout.

-- Extend organizations with org_type
ALTER TABLE organizations
    ADD COLUMN org_type      ENUM('standard','agency','sub_account') NOT NULL DEFAULT 'standard' AFTER name,
    ADD COLUMN parent_org_id BIGINT UNSIGNED NULL DEFAULT NULL AFTER org_type;

-- White-label config keys will live in system_settings:
--   white_label.domain      VARCHAR   -  custom domain for agency portal
--   white_label.logo_url    VARCHAR   -  hosted logo URL
--   white_label.brand_color VARCHAR   -  hex colour for agency branding
--   white_label.brand_name  VARCHAR   -  custom product name (replaces "B-connex")

-- Agency billing plan  -  only columns that exist in plans table
INSERT IGNORE INTO plans (slug, name, tier, price_aud_cents, seats, active)
VALUES ('agency', 'Agency', 'enterprise', 79900, 999, 1);
