from __future__ import annotations

import csv
from pathlib import Path

OUT = Path(__file__).resolve().parent

keywords = [
    # Category / platform
    ("Category", "seo mcp server", "Commercial investigation", "Decision", "/resources/seo-mcp-server-guide/", "Guide", "P0", "Own the category definition and connect it to the product."),
    ("Category", "mcp server for seo", "Commercial investigation", "Decision", "/", "Homepage", "P0", "Primary category variation."),
    ("Category", "ai seo platform", "Commercial", "Decision", "/platform/", "Product", "P0", "Differentiate agent-native access from dashboard-only tools."),
    ("Category", "agentic seo platform", "Commercial", "Decision", "/platform/", "Product", "P0", "Use operating-loop proof, not vague automation language."),
    ("Category", "seo tools for ai agents", "Commercial", "Decision", "/", "Homepage", "P0", "High-fit parent concept."),
    ("Category", "ai agent seo tools", "Commercial", "Decision", "/", "Homepage", "P0", "Close variant for homepage and platform copy."),
    ("Category", "live seo data for ai", "Commercial", "Decision", "/platform/", "Product", "P1", "Emphasize freshness and authorized project scope."),
    ("Category", "seo intelligence platform", "Commercial", "Decision", "/platform/", "Product", "P1", "Broader category; explain evidence-to-action workflow."),
    ("Category", "ai native seo software", "Commercial", "Decision", "/platform/", "Product", "P1", "Use only where the page demonstrates native agent access."),
    ("Category", "seo automation with ai agents", "Informational-commercial", "Consideration", "/resources/agentic-seo-workflow/", "Guide", "P1", "Clarify permission, review, and verification."),
    # MCP / architecture
    ("MCP", "what is an seo mcp server", "Informational", "Awareness", "/resources/seo-mcp-server-guide/", "Guide", "P0", "Direct-answer opening and architecture diagram."),
    ("MCP", "seo mcp tools", "Commercial", "Consideration", "/features/", "Hub", "P0", "Map individual tool jobs to features."),
    ("MCP", "technical seo mcp", "Commercial", "Consideration", "/features/site-audit/", "Feature", "P1", "Audit retrieval and repository handoff."),
    ("MCP", "keyword research mcp", "Commercial", "Consideration", "/features/keyword-research/", "Feature", "P1", "Keyword exploration and batch analysis."),
    ("MCP", "rank tracking mcp", "Commercial", "Consideration", "/features/rank-tracking/", "Feature", "P1", "Current movement and GSC context."),
    ("MCP", "backlink mcp server", "Commercial", "Consideration", "/features/", "Future feature", "P2", "Create only after backlink page and live tool are production-ready."),
    ("MCP", "mcp vs api for ai agents", "Informational", "Consideration", "/resources/seo-api-for-ai-agents/", "Guide", "P1", "Compare transport and discovery, not which is universally better."),
    ("MCP", "how to connect an mcp server", "Informational", "Activation", "/connect/", "Setup", "P1", "Use client tabs and tested config."),
    ("MCP", "mcp server authentication", "Informational", "Implementation", "/docs/", "Docs", "P2", "Token safety, scope, rotation, and revocation."),
    ("MCP", "mcp tool schema best practices", "Informational", "Implementation", "/resources/seo-api-for-ai-agents/", "Guide", "P2", "Future dedicated developer article."),
    # API
    ("API", "seo api for ai agents", "Commercial", "Decision", "/resources/seo-api-for-ai-agents/", "Guide", "P0", "Primary developer/API intent."),
    ("API", "ai seo api", "Commercial", "Decision", "/docs/", "Docs", "P0", "Lead with MCP plus HTTP options."),
    ("API", "seo data api for llm", "Commercial", "Consideration", "/docs/", "Docs", "P1", "Use task-oriented examples and scope limits."),
    ("API", "technical seo audit api", "Commercial", "Decision", "/features/site-audit/", "Feature", "P1", "Describe latest audit and evidence retrieval."),
    ("API", "keyword research api for ai", "Commercial", "Decision", "/features/keyword-research/", "Feature", "P1", "Intent, related terms, batch workflows."),
    ("API", "competitor keyword gap api", "Commercial", "Decision", "/features/competitor-analysis/", "Feature", "P1", "Practical coverage gaps and page opportunities."),
    ("API", "rank tracking api for agents", "Commercial", "Consideration", "/features/rank-tracking/", "Feature", "P2", "Create exact page only if dedicated endpoint is stable."),
    ("API", "seo api bearer token", "Informational", "Implementation", "/docs/", "Docs", "P2", "Authentication example and security caveats."),
    ("API", "agent ready api design", "Informational", "Awareness", "/resources/seo-api-for-ai-agents/", "Guide", "P2", "Broader architecture discovery."),
    ("API", "seo api response schema", "Informational", "Implementation", "/resources/seo-api-for-ai-agents/", "Guide", "P2", "Freshness, partial data, stable IDs, pagination."),
    # Cursor
    ("Cursor", "seo tools for cursor", "Commercial", "Decision", "/integrations/cursor/", "Integration", "P0", "Primary integration target."),
    ("Cursor", "cursor seo mcp", "Commercial", "Activation", "/integrations/cursor/", "Integration", "P0", "Exact config and first prompt."),
    ("Cursor", "technical seo with cursor", "Informational-commercial", "Consideration", "/integrations/cursor/", "Integration", "P1", "Repository-aware audit implementation."),
    ("Cursor", "cursor ai seo workflow", "Informational-commercial", "Consideration", "/integrations/cursor/", "Integration", "P1", "Audit-to-code operating loop."),
    ("Cursor", "cursor mcp seo server setup", "Informational", "Activation", "/integrations/cursor/", "Integration", "P1", "Use exact path for Windows, macOS, and Linux."),
    ("Cursor", "use cursor for technical seo audit", "Informational", "Consideration", "/resources/cursor-technical-seo-workflow/", "Future guide", "P1", "Create after recording a production workflow."),
    # Claude
    ("Claude", "claude seo tools", "Commercial", "Decision", "/integrations/claude/", "Integration", "P0", "Cover Desktop and Code explicitly."),
    ("Claude", "claude seo mcp", "Commercial", "Activation", "/integrations/claude/", "Integration", "P0", "MCP setup and first calls."),
    ("Claude", "claude code seo workflow", "Informational-commercial", "Consideration", "/integrations/claude/", "Integration", "P1", "Repo-aware plans and verification."),
    ("Claude", "connect claude to seo data", "Informational", "Activation", "/integrations/claude/", "Integration", "P1", "Explain token, config, and data scope."),
    ("Claude", "claude desktop seo mcp server", "Informational-commercial", "Activation", "/integrations/claude/", "Integration", "P1", "Dedicated subsection; split later only if needed."),
    ("Claude", "use claude for technical seo", "Informational", "Consideration", "/resources/claude-code-seo-workflow/", "Future guide", "P1", "Create from a tested workflow."),
    # ChatGPT
    ("ChatGPT", "chatgpt seo api", "Commercial", "Decision", "/integrations/chatgpt/", "Integration", "P0", "Explain HTTP/Bearer path and custom agent use."),
    ("ChatGPT", "connect chatgpt to seo data", "Informational-commercial", "Activation", "/integrations/chatgpt/", "Integration", "P0", "Avoid implying unsupported native MCP."),
    ("ChatGPT", "custom gpt seo api", "Commercial", "Activation", "/integrations/chatgpt/", "Integration", "P1", "Use current platform terminology at publication."),
    ("ChatGPT", "live seo data in chatgpt", "Commercial", "Consideration", "/integrations/chatgpt/", "Integration", "P1", "Project-scoped retrieval and auth."),
    ("ChatGPT", "chatgpt technical seo workflow", "Informational", "Consideration", "/integrations/chatgpt/", "Integration", "P2", "Emphasize review and non-code tasks unless connected to code tools."),
    # Windsurf / VS Code
    ("Windsurf", "windsurf seo tools", "Commercial", "Decision", "/integrations/windsurf/", "Integration", "P1", "Client-specific setup and use cases."),
    ("Windsurf", "windsurf seo mcp", "Commercial", "Activation", "/integrations/windsurf/", "Integration", "P1", "Exact config and prompt proof."),
    ("Windsurf", "technical seo in windsurf", "Informational-commercial", "Consideration", "/integrations/windsurf/", "Integration", "P2", "Repo-aware workflow."),
    ("VS Code", "vscode seo tools", "Commercial", "Decision", "/integrations/vscode/", "Integration", "P1", "Frame around agent/Copilot workflows."),
    ("VS Code", "vscode mcp seo server", "Commercial", "Activation", "/integrations/vscode/", "Integration", "P1", "Exact setup."),
    ("VS Code", "copilot seo tools", "Commercial", "Consideration", "/integrations/vscode/", "Integration", "P2", "Verify current product support before stronger claims."),
    # Feature
    ("Audit", "ai technical seo audit tool", "Commercial", "Decision", "/features/site-audit/", "Feature", "P0", "Show evidence, affected URLs, and agent handoff."),
    ("Audit", "technical seo audit for developers", "Commercial", "Decision", "/features/site-audit/", "Feature", "P1", "Code implementation and verification."),
    ("Audit", "seo audit tool with api", "Commercial", "Decision", "/features/site-audit/", "Feature", "P1", "MCP plus HTTP."),
    ("Audit", "prioritize seo audit issues", "Informational", "Consideration", "/features/site-audit/", "Feature", "P1", "Impact-effort-confidence framework."),
    ("Keywords", "ai keyword research tool for agents", "Commercial", "Decision", "/features/keyword-research/", "Feature", "P1", "Differentiate retrieval from generic generation."),
    ("Keywords", "keyword explorer api", "Commercial", "Decision", "/features/keyword-research/", "Feature", "P1", "Exact metrics and intent where supported."),
    ("Keywords", "bulk keyword analysis api", "Commercial", "Decision", "/features/keyword-research/", "Feature", "P2", "Feature-specific content and exports."),
    ("Competitors", "ai competitor keyword gap tool", "Commercial", "Decision", "/features/competitor-analysis/", "Feature", "P1", "Practical openings and page mapping."),
    ("Competitors", "seo competitor analysis api", "Commercial", "Decision", "/features/competitor-analysis/", "Feature", "P1", "Structured retrieval for agents."),
    ("Rankings", "ai rank tracking tool", "Commercial", "Decision", "/features/rank-tracking/", "Feature", "P1", "Combine movement with workspace context."),
    ("Rankings", "google search console ai agent", "Commercial", "Consideration", "/features/rank-tracking/", "Feature", "P1", "Potential future dedicated page."),
    ("Content", "ai content brief api", "Commercial", "Decision", "/features/content-workflows/", "Feature", "P1", "Evidence-backed briefs and handoff."),
    ("Content", "agentic content workflow seo", "Informational-commercial", "Consideration", "/features/content-workflows/", "Feature", "P2", "Prioritize before generation."),
    # Audience
    ("Developers", "seo tools for developers", "Commercial", "Decision", "/solutions/developers/", "Solution", "P0", "Repository and implementation proof."),
    ("Developers", "technical seo automation for developers", "Commercial", "Consideration", "/solutions/developers/", "Solution", "P1", "Bounded permissions and verification."),
    ("Agencies", "ai seo platform for agencies", "Commercial", "Decision", "/solutions/agencies/", "Solution", "P1", "Multi-project standardization, not fake white label claims."),
    ("Agencies", "seo workflow automation agency", "Commercial", "Consideration", "/solutions/agencies/", "Solution", "P1", "Research-to-brief-to-dev handoff."),
    ("Founders", "seo tools for saas founders", "Commercial", "Decision", "/solutions/founders/", "Solution", "P1", "Bottleneck and category decisions."),
    ("Founders", "ai seo tool for small team", "Commercial", "Decision", "/solutions/founders/", "Solution", "P1", "Free entry and focused queue."),
    ("Publishers", "ai seo platform for publishers", "Commercial", "Decision", "/solutions/publishers/", "Solution", "P1", "Editorial prioritization and refresh."),
    ("Publishers", "seo workflow for affiliate sites", "Informational-commercial", "Consideration", "/solutions/publishers/", "Solution", "P2", "Avoid mass content framing."),
    # Pricing/comparison
    ("Pricing", "seo mcp server pricing", "Commercial", "Decision", "/pricing/", "Pricing", "P0", "Free core workflow and transparent Pro upgrade."),
    ("Pricing", "free seo mcp server", "Commercial", "Decision", "/pricing/", "Pricing", "P0", "Accurate limits and no bait-and-switch."),
    ("Pricing", "free ai seo api", "Commercial", "Decision", "/pricing/", "Pricing", "P1", "Clarify included workflow and limits."),
    ("Comparison", "best seo mcp server", "Commercial investigation", "Decision", "/resources/best-seo-mcp-server/", "Future comparison", "P1", "Publish only with documented methodology and current testing."),
    ("Comparison", "seo mcp server comparison", "Commercial investigation", "Decision", "/resources/seo-mcp-server-comparison/", "Future comparison", "P1", "Compare access, data, freshness, tools, security, and workflow."),
    ("Comparison", "seo api vs seo dashboard", "Informational-commercial", "Consideration", "/resources/seo-mcp-server-guide/", "Guide", "P2", "Explain jobs of each interface."),
]

with (OUT / "keyword-plan.csv").open("w", newline="", encoding="utf-8-sig") as f:
    writer = csv.writer(f)
    writer.writerow(["cluster", "primary_keyword", "intent", "funnel_stage", "target_url", "page_type", "priority", "implementation_note"])
    writer.writerows(keywords)

content = [
    (1, "SEO MCP server guide", "/resources/seo-mcp-server-guide/", "Category", "Published in package", "Definition, architecture, tools, setup, security, evaluation"),
    (2, "Agentic SEO workflow", "/resources/agentic-seo-workflow/", "Workflow", "Published in package", "Evidence to decision, delivery, verification, measurement"),
    (3, "SEO API for AI agents", "/resources/seo-api-for-ai-agents/", "Developer", "Published in package", "Auth, endpoints, response design, errors, freshness, evaluation"),
    (4, "Cursor technical SEO workflow", "/resources/cursor-technical-seo-workflow/", "Integration", "Next", "Tested setup, audit retrieval, repo plan, diff, validation"),
    (5, "Claude Code SEO workflow", "/resources/claude-code-seo-workflow/", "Integration", "Next", "Desktop vs Code, setup, prompts, code/content use cases"),
    (6, "MCP vs REST API for agents", "/resources/mcp-vs-rest-api/", "Architecture", "Next", "Discovery, transport, auth, use cases, hybrid design"),
    (7, "How SearchSignal opportunity scoring works", "/resources/seo-opportunity-scoring/", "Methodology", "Next", "Impact, effort, confidence, evidence, limitations"),
    (8, "Search Console data for AI agents", "/resources/search-console-ai-agent/", "Data", "Next", "Coverage, freshness, query-page relations, interpretation"),
    (9, "Repository-aware SEO implementation plans", "/resources/repository-aware-seo/", "Developer", "Planned", "Map evidence to routes, components, tests, and proof"),
    (10, "SEO agent security and permissions", "/resources/seo-agent-security/", "Security", "Planned", "Read-only start, token scope, writes, logging, rollback"),
    (11, "How to evaluate AI SEO tools", "/resources/evaluate-ai-seo-tools/", "Evaluation", "Planned", "Data quality, workflow, verification, claims, cost"),
    (12, "Technical SEO audit workflow for developers", "/resources/technical-seo-audit-developers/", "Feature", "Planned", "Crawl, prioritize, map, fix, validate"),
    (13, "How to build an SEO agent with MCP", "/resources/build-seo-agent-mcp/", "Developer", "Planned", "Tool catalog, schemas, auth, retrieval, evaluation"),
    (14, "Keyword research inside an AI agent", "/resources/keyword-research-ai-agent/", "Feature", "Planned", "Intent, metrics, SERP patterns, clusters, briefs"),
    (15, "Competitor gap analysis for agents", "/resources/competitor-gap-ai-agent/", "Feature", "Planned", "Coverage gaps, feasibility, page mapping, evidence"),
    (16, "AI-assisted rank tracking interpretation", "/resources/rank-tracking-ai-agent/", "Feature", "Planned", "Movement, volatility, GSC, causality limits"),
    (17, "SEO agency workspace standard", "/resources/agency-agentic-seo-workflow/", "Agency", "Planned", "Client setup, evidence packs, briefs, approvals, reporting"),
    (18, "Publisher refresh queue with AI", "/resources/publisher-refresh-queue/", "Publisher", "Planned", "Positions 4–15, impressions, intent, update size, tracking"),
    (19, "Prevent content cannibalization with agents", "/resources/ai-content-cannibalization/", "Publisher", "Planned", "Overlap, merge, reposition, redirect, verify"),
    (20, "Build vs buy an SEO agent data layer", "/resources/build-vs-buy-seo-agent-data/", "Commercial", "Planned", "Provider costs, auth, tooling, freshness, maintenance"),
    (21, "SEO MCP server comparison methodology", "/resources/seo-mcp-server-comparison/", "Comparison", "Later", "Tested matrix; never fabricate competitor capabilities"),
    (22, "SearchSignal product changelog", "/changelog/", "Trust", "Next", "Versioned tools, clients, API, data, fixes, deprecations"),
    (23, "SearchSignal data and methodology", "/methodology/", "Trust", "Next", "Sources, metrics, freshness, estimates, scoring, limitations"),
    (24, "SearchSignal security overview", "/security/", "Trust", "Next", "Token handling, authorization, logging, vendors, disclosure process"),
]
with (OUT / "content-roadmap.csv").open("w", newline="", encoding="utf-8-sig") as f:
    writer = csv.writer(f)
    writer.writerow(["order", "topic", "proposed_url", "cluster", "status", "required_depth"])
    writer.writerows(content)

analytics = [
    ("page_view", "Every public page", "Path, title, referrer, campaign", "Baseline traffic", "No private project data"),
    ("nav_start_free", "Header Start free", "Path, label", "Acquisition CTA", ""),
    ("nav_login", "Header Log in", "Path", "Returning-user route", ""),
    ("announcement_connect", "Announcement connect link", "Path", "Announcement effectiveness", ""),
    ("hero_start_free", "Homepage primary CTA", "Variant, path", "Homepage conversion", ""),
    ("hero_watch_setup", "Homepage setup CTA", "Path", "Education intent", ""),
    ("cta_start_free", "Reusable CTA start", "Path, section", "Page conversion", ""),
    ("cta_see_setup", "Reusable CTA setup", "Path, section", "Setup interest", ""),
    ("integration_select", "Client card or tab selected", "Client, path", "Client demand", ""),
    ("config_copy", "Client config copied", "Client, config type", "Activation step", "Never include token"),
    ("docs_code_copy", "Documentation code copied", "Snippet ID, path", "Developer activation", ""),
    ("prompt_demo_run", "Homepage prompt demo selected", "Demo type, path", "Message resonance", ""),
    ("pricing_plan_select", "Free or Pro selected", "Plan, source page", "Plan intent", ""),
    ("signup_started", "Signup form viewed or begun", "Source path, campaign", "Funnel", "Server-side preferred"),
    ("signup_completed", "Account created", "Source path, campaign", "Funnel", "No email in analytics"),
    ("project_created", "First project created", "Plan, source", "Activation", "Do not send private domain by default"),
    ("audit_started", "Audit requested", "Plan, page limit", "Activation", ""),
    ("audit_completed", "Audit completed", "Plan, duration bucket, page count", "Activation", ""),
    ("token_created", "MCP/API token created", "Plan", "Core activation", "Never send token or fragment"),
    ("token_rotated", "Token rotated", "Reason bucket", "Security operations", "Never send token"),
    ("token_revoked", "Token revoked", "Reason bucket", "Security operations", ""),
    ("client_config_viewed", "Client setup opened", "Client", "Activation", ""),
    ("client_config_copied", "Authenticated config copied", "Client, transport", "Activation", "Never send config body"),
    ("connection_test_started", "Connection test initiated", "Client, transport", "Activation", ""),
    ("connection_test_succeeded", "Connection test passed", "Client, transport", "Activation", "North-star precursor"),
    ("first_tool_call_succeeded", "First real project tool call passed", "Client, tool, transport, plan", "North-star activation", "Do not send prompt or response"),
    ("second_active_day", "Activated user returns on a later day", "Client count, plan", "Retention", "Computed server-side"),
    ("pro_checkout_started", "Pro checkout initiated", "Source, plan", "Revenue", ""),
    ("pro_checkout_completed", "Pro purchase completed", "Source, plan", "Revenue", "Server-side purchase event"),
    ("resource_to_connect", "Resource reader clicks Connect", "Article slug", "Content-assisted conversion", ""),
    ("error_shown", "Public or activation error displayed", "Error code, step, client", "Reliability", "No sensitive details"),
]
with (OUT / "analytics-event-map.csv").open("w", newline="", encoding="utf-8-sig") as f:
    writer = csv.writer(f)
    writer.writerow(["event", "trigger", "parameters", "business_question", "privacy_note"])
    writer.writerows(analytics)

experiments = [
    (1, "Homepage primary CTA", "Start free — get your token", "Connect your AI free", "Activated token rate", "Medium", "Run after baseline tracking"),
    (2, "Homepage hero visual", "Agent tool-call console", "Product workspace dashboard", "CTA click and activation", "High", "Do not run with CTA test simultaneously"),
    (3, "Proof position", "Proof row under CTA", "Free-plan card under CTA", "Signup start", "Low", "Fast test"),
    (4, "Integration CTA", "Start free", "Generate Cursor config", "Token creation", "Medium", "Use client-specific wording"),
    (5, "Pricing framing", "Free and Pro side by side", "Start-free narrative then Pro depth", "Plan selection and activation", "Medium", "Watch Pro revenue, not only free signups"),
    (6, "Connect page order", "Token first, client second", "Client first, token second", "Config copied", "Medium", "Requires authenticated funnel data"),
    (7, "Docs CTA", "Create free token", "Test the API in browser", "First successful call", "High", "Only if secure test console exists"),
    (8, "Resource inline CTA", "Connect after architecture", "Connect after first example", "Resource-to-activation", "Low", "Test on highest-traffic guide"),
    (9, "Developer page proof", "File-by-file sample plan", "60-second workflow video", "Activation", "High", "Video must use real product"),
    (10, "Signup friction", "Standard form", "Single-sign-on first", "Signup completion and quality", "High", "Depends on auth stack"),
    (11, "Activation checklist", "No checklist", "Project → audit → token → test checklist", "First successful call", "High", "Likely strong product test"),
    (12, "First prompt", "Latest audit", "Workspace pack with top opportunities", "Second tool call and retention", "Medium", "Choose based on user role"),
]
with (OUT / "conversion-experiment-backlog.csv").open("w", newline="", encoding="utf-8-sig") as f:
    writer = csv.writer(f)
    writer.writerow(["priority", "surface", "control", "variant", "primary_metric", "effort", "note"])
    writer.writerows(experiments)

print(f"Wrote {len(keywords)} keyword targets, {len(content)} content items, {len(analytics)} analytics events, and {len(experiments)} experiments")
