from datetime import datetime
from typing import Optional
from uuid import UUID
from pydantic import BaseModel


class AccountSummary(BaseModel):
    id: UUID
    name: str
    display_code: Optional[str] = None

    model_config = {"from_attributes": True}


class SubscriptionSummary(BaseModel):
    id: UUID
    plan: str
    status: str
    current_period_start: Optional[datetime] = None
    current_period_end: Optional[datetime] = None

    model_config = {"from_attributes": True}


class SessionSummary(BaseModel):
    id: UUID
    tree_name: Optional[str] = None
    started_at: datetime
    completed_at: Optional[datetime] = None
    outcome: Optional[str] = None

    model_config = {"from_attributes": True}


class AuditLogSummary(BaseModel):
    id: UUID
    action: str
    resource_type: Optional[str] = None
    resource_id: Optional[str] = None
    created_at: datetime
    details: Optional[dict] = None

    model_config = {"from_attributes": True}


class InviteCodeUsedSummary(BaseModel):
    code: str
    assigned_plan: str
    trial_duration_days: Optional[int] = None
    created_by_email: Optional[str] = None

    model_config = {"from_attributes": True}


class UserDetailResponse(BaseModel):
    id: UUID
    email: str
    full_name: Optional[str] = None
    role: str
    is_active: bool
    is_super_admin: bool
    is_team_admin: bool
    created_at: datetime
    deleted_at: Optional[datetime] = None

    account: Optional[AccountSummary] = None
    subscription: Optional[SubscriptionSummary] = None
    invite_code_used: Optional[InviteCodeUsedSummary] = None

    recent_sessions: list[SessionSummary] = []
    total_sessions: int = 0
    recent_audit_logs: list[AuditLogSummary] = []
    total_audit_logs: int = 0
