# ============================================================================
# Cloudflare Pages — goadvisors-lp
#
# Everything runs inside the Go Advisors Cloudflare account. No third-party
# analytics, no data leaving the platform.
#
# FIRST-TIME SETUP (run in this order)
#
#   1. npm install -g wrangler && wrangler login
#
#   2. Create the database and copy the returned database_id into this file:
#        wrangler d1 create goadvisors-lp
#
#   3. Apply the schema (remote = the real database, not a local copy):
#        wrangler d1 execute goadvisors-lp --remote --file=./schema.sql
#
#   4. Create the Pages project (build command empty, output dir = repo root):
#        wrangler pages project create goadvisors-lp --production-branch=main
#
#   5. Set the dashboard token — generate a long random one, keep it in 1Password:
#        wrangler pages secret put DASH_TOKEN --project-name=goadvisors-lp
#
#   5b. Set the ERP intake secret (shared with goadvisors.clickgrow.tech —
#       the value the ERP expects in the x-lp-secret header). Never in this file:
#        wrangler pages secret put LP_LEAD_SECRET --project-name=goadvisors-lp
#
#   5c. If the database already existed before the leads table was added,
#       apply the migration (idempotent — safe to re-run):
#        wrangler d1 execute goadvisors-lp --remote --file=./migrations-d1/002-leads.sql
#
#   6. Deploy:
#        wrangler pages deploy . --project-name=goadvisors-lp
#
#   7. Bind D1 to the Pages project. This is the step people forget, and the
#      symptom is a dashboard that shows zeros forever:
#        Cloudflare dashboard → Workers & Pages → goadvisors-lp → Settings
#        → Bindings → D1 database → Variable name: DB → goadvisors-lp
#      Apply it to BOTH Production and Preview.
#
#   8. Add the custom domain lp.goadvisors.co, then the CNAME on GoDaddy.
#      See DNS-PLAN.md §3.
#
# VERIFY IT IS ACTUALLY WORKING
#   curl -sI https://lp.goadvisors.co/ | grep -i x-ga-
#     → should print X-GA-Variant, X-GA-Channel, X-GA-Bot, X-GA-QA
#   wrangler d1 execute goadvisors-lp --remote \
#     --command="SELECT variant, COUNT(*) FROM events GROUP BY variant;"
# ============================================================================

name = "goadvisors-lp"
compatibility_date = "2026-01-01"
pages_build_output_dir = "."

# --- D1 -----------------------------------------------------------------------
# Replace database_id with the value printed by `wrangler d1 create`.
# The binding name MUST be DB — that is what functions/ reads.
[[d1_databases]]
binding = "DB"
database_name = "goadvisors-lp"
database_id = "d1a99c4d-5dd4-4b91-9388-c067590bf0dd"

# --- vars ---------------------------------------------------------------------
# DASH_TOKEN is a SECRET and must NOT be written here. Use:
#   wrangler pages secret put DASH_TOKEN --project-name=goadvisors-lp
[vars]
EXPERIMENT = "lp-3way-2026-08"
