"""
Banner consent schemas — cookie consent SDK + admin configuration.

Phase 1 Step 4: extracted from ``compliance.api.banner_routes`` so the
route layer becomes thin delegation to ``compliance.services.banner_*``.
"""

from typing import Any, List, Optional

from pydantic import BaseModel, ConfigDict


class ConsentCreate(BaseModel):
    """Request body for recording a device consent."""
    site_id: str
    device_fingerprint: str
    categories: List[str] = []
    vendors: List[str] = []
    vendor_consents: dict[str, bool] = {}
    ip_address: Optional[str] = None
    user_agent: Optional[str] = None
    consent_string: Optional[str] = None
    # Vendor-agnostische Felder (Migration 107)
    consent_method: Optional[str] = None
    page_url: Optional[str] = None
    referrer: Optional[str] = None
    device_type: Optional[str] = None
    browser: Optional[str] = None
    os: Optional[str] = None
    screen_resolution: Optional[str] = None
    session_id: Optional[str] = None
    consent_scope: Optional[str] = None
    timezone: Optional[str] = None
    # Script/Cookie-Tracking (Migration 108)
    scripts_blocked: List[dict[str, Any]] = []
    scripts_released: List[dict[str, Any]] = []
    cookies_set: List[dict[str, Any]] = []


class SiteConfigCreate(BaseModel):
    """Request body for creating a banner site configuration."""
    site_id: str
    site_name: Optional[str] = None
    site_url: Optional[str] = None
    banner_title: Optional[str] = None
    banner_description: Optional[str] = None
    privacy_url: Optional[str] = None
    imprint_url: Optional[str] = None
    dsb_name: Optional[str] = None
    dsb_email: Optional[str] = None
    theme: Optional[dict[str, Any]] = None
    tcf_enabled: bool = False


class SiteConfigUpdate(BaseModel):
    """Partial update for a banner site configuration."""

    model_config = ConfigDict(extra="ignore")

    site_name: Optional[str] = None
    site_url: Optional[str] = None
    banner_title: Optional[str] = None
    banner_description: Optional[str] = None
    privacy_url: Optional[str] = None
    imprint_url: Optional[str] = None
    dsb_name: Optional[str] = None
    dsb_email: Optional[str] = None
    theme: Optional[dict[str, Any]] = None
    tcf_enabled: Optional[bool] = None
    is_active: Optional[bool] = None


class CategoryConfigCreate(BaseModel):
    """Request body for adding a cookie category to a site."""
    category_key: str
    name_de: str
    name_en: Optional[str] = None
    description_de: Optional[str] = None
    description_en: Optional[str] = None
    is_required: bool = False
    sort_order: int = 0


class VendorConfigCreate(BaseModel):
    """Request body for adding a vendor under a site's category."""
    vendor_name: str
    vendor_url: Optional[str] = None
    category_key: str
    description_de: Optional[str] = None
    description_en: Optional[str] = None
    cookie_names: List[str] = []
    retention_days: int = 365


class LinkEmailRequest(BaseModel):
    """Request body for linking an email to a device fingerprint."""
    site_id: str
    device_fingerprint: str
    email: str


class ConsentSyncRequest(BaseModel):
    """Request body for syncing banner consent to Einwilligungen."""
    site_id: str
    device_fingerprint: str
    email: str


__all__ = [
    "ConsentCreate",
    "SiteConfigCreate",
    "SiteConfigUpdate",
    "CategoryConfigCreate",
    "VendorConfigCreate",
    "LinkEmailRequest",
    "ConsentSyncRequest",
]
