"""Schemas for sidebar stats endpoint."""

from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel


class SidebarActiveSession(BaseModel):
    """An active or paused session for the activity feed."""
    session_id: UUID
    tree_name: str
    tree_id: UUID
    tree_type: str
    started_at: datetime
    ticket_number: Optional[str] = None
    psa_ticket_id: Optional[str] = None


class SidebarRecentSession(BaseModel):
    """A recently completed session for the activity feed."""
    session_id: UUID
    tree_name: str
    tree_id: UUID
    tree_type: str
    completed_at: datetime


class SidebarTreeCounts(BaseModel):
    """Tree counts for All Flows sub-items."""
    total: int
    troubleshooting: int
    procedural: int
    maintenance: int


class SidebarStatsResponse(BaseModel):
    """Response for GET /sessions/sidebar-stats."""
    resolved_today: int
    active_count: int
    total_session_minutes_today: int
    escalation_count: int = 0
    tree_counts: SidebarTreeCounts
    active_sessions: list[SidebarActiveSession]
    recent_completions: list[SidebarRecentSession]
