# app/modules/prospecting/routes/pages/admin.py
"""
Prospecting Admin Page Routes (HTML rendering).

Admin pages for lead discovery and campaign management:
- Dashboard - Overview with stats and charts
- Prospects - Prospect list with filters
- Prospect Detail - Single prospect view with tabs
- Leads - Scored lead list
- Quick Capture - Mobile-friendly lead capture form
- Scan Jobs - Scan job monitoring
- Campaigns - Campaign template management
"""

from fastapi import APIRouter, Depends, Path, Request
from fastapi.responses import HTMLResponse
from sqlalchemy.orm import Session

from app.api.deps import get_db, require_menu_access
from app.modules.core.utils.page_context import get_admin_context
from app.modules.enums import FrontendType
from app.modules.tenancy.models import User
from app.templates_config import templates

router = APIRouter()


@router.get("/prospecting", response_class=HTMLResponse, include_in_schema=False)
async def admin_prospecting_dashboard(
    request: Request,
    current_user: User = Depends(require_menu_access("prospecting-dashboard", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render prospecting dashboard page."""
    return templates.TemplateResponse(
        "prospecting/admin/dashboard.html",
        get_admin_context(request, db, current_user),
    )


@router.get("/prospecting/prospects", response_class=HTMLResponse, include_in_schema=False)
async def admin_prospects_list(
    request: Request,
    current_user: User = Depends(require_menu_access("prospects", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render prospects list page."""
    return templates.TemplateResponse(
        "prospecting/admin/prospects.html",
        get_admin_context(request, db, current_user),
    )


@router.get(
    "/prospecting/prospects/{prospect_id}",
    response_class=HTMLResponse,
    include_in_schema=False,
)
async def admin_prospect_detail(
    request: Request,
    prospect_id: int = Path(..., description="Prospect ID"),
    current_user: User = Depends(require_menu_access("prospects", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render single prospect detail page."""
    context = get_admin_context(request, db, current_user)
    context["prospect_id"] = prospect_id
    return templates.TemplateResponse(
        "prospecting/admin/prospect-detail.html",
        context,
    )


@router.get("/prospecting/leads", response_class=HTMLResponse, include_in_schema=False)
async def admin_leads_list(
    request: Request,
    current_user: User = Depends(require_menu_access("leads", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render leads list page."""
    return templates.TemplateResponse(
        "prospecting/admin/leads.html",
        get_admin_context(request, db, current_user),
    )


@router.get("/prospecting/capture", response_class=HTMLResponse, include_in_schema=False)
async def admin_quick_capture(
    request: Request,
    current_user: User = Depends(require_menu_access("capture", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render mobile-friendly quick capture form."""
    return templates.TemplateResponse(
        "prospecting/admin/capture.html",
        get_admin_context(request, db, current_user),
    )


@router.get("/prospecting/scan-jobs", response_class=HTMLResponse, include_in_schema=False)
async def admin_scan_jobs(
    request: Request,
    current_user: User = Depends(require_menu_access("scan-jobs", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render scan jobs monitoring page."""
    return templates.TemplateResponse(
        "prospecting/admin/scan-jobs.html",
        get_admin_context(request, db, current_user),
    )


@router.get("/prospecting/campaigns", response_class=HTMLResponse, include_in_schema=False)
async def admin_campaigns(
    request: Request,
    current_user: User = Depends(require_menu_access("campaigns", FrontendType.ADMIN)),
    db: Session = Depends(get_db),
):
    """Render campaign management page."""
    return templates.TemplateResponse(
        "prospecting/admin/campaigns.html",
        get_admin_context(request, db, current_user),
    )
