"""Add feature_flags table for per-feature gating.

Replaces the global WAITLIST_MODE env var with granular per-feature flags
that can be toggled at runtime via the admin UI.
"""


def up(conn):
    conn.execute("""
        CREATE TABLE IF NOT EXISTS feature_flags (
            name        TEXT PRIMARY KEY,
            enabled     INTEGER NOT NULL DEFAULT 0,
            description TEXT,
            updated_at  TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
        )
    """)

    # Seed initial flags — markets live, everything else behind waitlist
    conn.executemany(
        "INSERT OR IGNORE INTO feature_flags (name, enabled, description) VALUES (?, ?, ?)",
        [
            ("markets", 0, "Market/SEO content pages"),
            ("payments", 0, "Paddle billing & checkout"),
            ("planner_export", 0, "Business plan PDF export"),
            ("supplier_signup", 0, "Supplier onboarding wizard"),
            ("lead_unlock", 0, "Lead credit purchase & unlock"),
        ],
    )
