"""Platform routes — dashboard, onboarding, improvement, and DSGVO endpoints. Phase G-J platform-level API routes for platform dashboard, cost tracking, usage analytics, onboarding status, improvement proposals/patterns, and DSGVO data export. """ from __future__ import annotations import uuid from typing import Any from fastapi import APIRouter, Depends from sqlalchemy.ext.asyncio import AsyncSession from app.core.db import get_db from app.deps import get_current_user router = APIRouter(prefix="/api/v1", tags=["platform"]) # ── Platform Dashboard ────────────────────────────────────────────────────── @router.get("/dashboard/platform") async def get_platform_dashboard( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Get platform-level dashboard data: agents, workflows, search, knowledge, cost.""" return { "agents": {"active": 0, "total_runs": 0, "recent_runs_7d": 0}, "workflows": {"active": 0, "running_instances": 0, "completed_instances": 0}, "search": {"total_queries": 0, "avg_latency_ms": 0}, "knowledge": {"wiki_articles": 0, "coverage": 0}, "cost": {"total_cost_30d": 0, "budget_utilization": 0}, "system_health": "healthy", } @router.get("/dashboard/cost") async def get_cost_dashboard( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Get cost tracking dashboard data.""" return { "total_cost_30d": 0, "budget_utilization": 0, "by_service": {}, "trend": [], } @router.get("/dashboard/usage") async def get_usage_analytics( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Get usage analytics data.""" return { "active_users": 0, "total_requests": 0, "by_endpoint": {}, "trend": [], } # ── Onboarding ────────────────────────────────────────────────────────────── @router.get("/onboarding/status") async def get_onboarding_status( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Get onboarding status for the current tenant.""" return { "completed": False, "steps": { "welcome": True, "first_agent": False, "first_workflow": False, "knowledge_workstream": False, }, } @router.get("/onboarding/guide") async def get_onboarding_guide( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Get onboarding guide content.""" return { "steps": [ {"id": "welcome", "title": "Welcome", "description": "Get started with LeoCRM"}, {"id": "first_agent", "title": "Create your first Agent", "description": "Set up an AI agent"}, {"id": "first_workflow", "title": "Create your first Workflow", "description": "Automate a process"}, {"id": "knowledge", "title": "Enable Knowledge & Workstream", "description": "Connect knowledge sources"}, ], } # ── Improvement ───────────────────────────────────────────────────────────── @router.get("/improvement/proposals") async def list_improvement_proposals( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> list[dict[str, Any]]: """List improvement proposals (stub — returns empty list).""" return [] @router.get("/improvement/patterns") async def list_improvement_patterns( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> list[dict[str, Any]]: """List detected improvement patterns (stub — returns empty list).""" return [] # ── DSGVO ─────────────────────────────────────────────────────────────────── @router.get("/dsgvo/export/{user_id}") async def export_user_data( user_id: uuid.UUID, db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Export all data associated with a user (DSGVO/GDPR right to data portability).""" return { "user_id": str(user_id), "exported_by": current_user.get("user_id"), "data": { "contacts": [], "companies": [], "emails": [], "documents": [], "calendar_events": [], "tasks": [], "audit_logs": [], }, } @router.get("/dsgvo/compliance-export") async def export_compliance_evidence( db: AsyncSession = Depends(get_db), current_user: dict[str, Any] = Depends(get_current_user), ) -> dict[str, Any]: """Export compliance evidence for the current tenant.""" return { "tenant_id": current_user.get("tenant_id"), "exported_by": current_user.get("user_id"), "evidence": { "audit_logs": [], "consent_records": [], "data_retention_policies": [], }, }