"""Analytics Pydantic schemas.

Request/response models for the analytics API.

⚠️ AUTO-GENERATED BY PRISM — DO NOT EDIT
"""

from __future__ import annotations

from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field


class EventCreate(BaseModel):
    """Schema for creating an analytics event."""

    event_name: str = Field(..., max_length=255, description="Event name")
    category: str = Field(default="custom", max_length=100, description="Event category")
    properties: dict[str, Any] | None = Field(default=None, description="Event properties")
    page_url: str | None = Field(default=None, max_length=2048, description="Page URL")
    session_id: str | None = Field(default=None, max_length=255, description="Client session ID")


class EventResponse(BaseModel):
    """Schema for an analytics event response."""

    id: int
    event_name: str
    category: str
    properties: dict[str, Any] | None = None
    user_id: str | None = None
    session_id: str | None = None
    page_url: str | None = None
    timestamp: datetime

    model_config = {"from_attributes": True}


class EventsListResponse(BaseModel):
    """Paginated list of analytics events."""

    items: list[EventResponse]
    total: int
    page: int
    page_size: int

{% if track_page_views %}


class PageViewCreate(BaseModel):
    """Schema for recording a page view."""

    page_url: str = Field(..., max_length=2048, description="Viewed page URL")
    page_title: str | None = Field(default=None, max_length=255, description="Page title")
    session_id: str | None = Field(default=None, max_length=255, description="Client session ID")
{% if track_referrer %}
    referrer: str | None = Field(default=None, max_length=2048, description="Referrer URL")
{% endif %}
{% endif %}

{% if track_user_sessions %}


class SessionResponse(BaseModel):
    """Schema for a session response."""

    id: int
    session_id: str
    user_id: str | None = None
    started_at: datetime
    ended_at: datetime | None = None
    is_active: bool
    page_views: int
    events_count: int
    duration_seconds: float | None = None

    model_config = {"from_attributes": True}
{% endif %}

{% if dashboard_enabled %}


class AnalyticsSummary(BaseModel):
    """Dashboard summary statistics."""

    total_events: int = Field(description="Total events in period")
    total_sessions: int = Field(description="Total sessions in period")
    total_page_views: int = Field(description="Total page views in period")
    unique_users: int = Field(description="Unique users in period")
    avg_session_duration: float | None = Field(description="Average session duration in seconds")
    top_events: list[dict[str, Any]] = Field(description="Top events by count")
    top_pages: list[dict[str, Any]] = Field(description="Top pages by views")
    events_by_day: list[dict[str, Any]] = Field(description="Events grouped by day")
{% endif %}
