from datetime import datetime
from typing import Optional, Literal
from uuid import UUID
from pydantic import BaseModel, Field


class ShareCreate(BaseModel):
    visibility: Literal["public", "account"] = Field("public", description="Share visibility")
    share_name: Optional[str] = Field(None, max_length=100, description="Optional label for the share")
    expires_at: Optional[datetime] = Field(None, description="Optional expiration datetime")


class ShareResponse(BaseModel):
    id: UUID
    session_id: UUID
    account_id: UUID
    share_token: str
    share_name: Optional[str] = None
    visibility: str
    created_by: UUID
    created_at: datetime
    updated_at: datetime
    expires_at: Optional[datetime] = None
    view_count: int
    last_viewed_at: Optional[datetime] = None
    is_active: bool
    share_url: Optional[str] = None

    class Config:
        from_attributes = True


class SharePublicView(BaseModel):
    """Read-only session data returned when accessing a share link."""
    session_id: UUID
    tree_name: str
    tree_description: Optional[str] = None
    tree_structure: dict
    path_taken: list[str]
    decisions: list[dict]
    custom_steps: list[dict] = Field(default_factory=list)
    started_at: datetime
    completed_at: Optional[datetime] = None
    ticket_number: Optional[str] = None
    client_name: Optional[str] = None
    share_name: Optional[str] = None
    visibility: str
