"""Data models used by the desktop SSO client."""

from dataclasses import dataclass, field
from datetime import datetime, timedelta
from typing import Dict, Optional


@dataclass(frozen=True)
class AuthRequest:
    """Information required to start an authentication request."""

    auth_url: str
    email: str
    redirect_uri: str


@dataclass(frozen=True)
class TokenResponse:
    """Token response parsed from callback URL."""

    id_token: str
    refresh_token: Optional[str] = None
    access_token: Optional[str] = None
    token_type: Optional[str] = None
    expires_in: Optional[int] = None
    scope: Optional[str] = None
    state: Optional[str] = None
    raw_params: Dict[str, str] = field(default_factory=dict)

    @property
    def expires_at(self) -> Optional[datetime]:
        """Compute expiration timestamp from expires_in if available."""
        if self.expires_in is None:
            return None
        return datetime.utcnow() + timedelta(seconds=self.expires_in)
