"""
BreakPilot Customer Portal

Slim customer-facing frontend with:
- Login/Register
- My Consents view
- Data Export Request (GDPR)
- Legal Documents viewing
"""

from pathlib import Path
from fastapi import APIRouter
from fastapi.responses import HTMLResponse

router = APIRouter()

# Path to templates
TEMPLATES_DIR = Path(__file__).parent / "templates"


@router.get("/customer", response_class=HTMLResponse)
def customer_portal():
    """Serve the customer portal (new slim frontend)"""
    template_path = TEMPLATES_DIR / "customer.html"
    if template_path.exists():
        return template_path.read_text(encoding="utf-8")
    else:
        return """
        <!DOCTYPE html>
        <html lang="de">
        <head>
            <meta charset="UTF-8">
            <title>BreakPilot – Fehler</title>
        </head>
        <body>
            <h1>Template nicht gefunden</h1>
            <p>Die Template-Datei customer.html wurde nicht gefunden.</p>
        </body>
        </html>
        """


@router.get("/account")
async def account_redirect():
    """Redirect /account to /customer"""
    from fastapi.responses import RedirectResponse
    return RedirectResponse(url="/customer")


@router.get("/mein-konto")
async def mein_konto_redirect():
    """German URL redirect to /customer"""
    from fastapi.responses import RedirectResponse
    return RedirectResponse(url="/customer")
