"""POST /scan-cookie-matrix — fokussierter Multi-Browser Cookie-Test."""

from __future__ import annotations

import logging
from datetime import datetime, timezone

from fastapi import APIRouter
from pydantic import BaseModel

from services.cookie_behavior_per_browser import run_cookie_matrix

logger = logging.getLogger(__name__)
router = APIRouter()


class CookieMatrixReq(BaseModel):
    url: str
    browser_profiles: list[str] | None = None


@router.post("/scan-cookie-matrix")
async def scan_cookie_matrix(req: CookieMatrixReq):
    logger.info("Cookie-matrix scan %s profiles=%s",
                req.url, req.browser_profiles or "default")
    res = await run_cookie_matrix(req.url, req.browser_profiles)
    res["scanned_at"] = datetime.now(timezone.utc).isoformat()
    return res
