"""Device connection model for connected health devices and apps."""
from datetime import datetime
from typing import Literal, Optional

from pydantic import Field

from .base import BaseDocument
from .types import PyObjectId


class DeviceConnection(BaseDocument):
    """Represents a connection from the Samsung Health Android companion app."""
    userId: PyObjectId = Field(description="ID of the Hipograf user who owns this connection")
    provider: Literal['samsung_health'] = Field(
        default='samsung_health',
        description="Device provider identifier"
    )

    # Connection status
    status: Literal['active', 'expired', 'revoked', 'pending'] = Field(
        default='pending', description="Current status of this connection"
    )
    lastSyncAt: Optional[datetime] = Field(
        default=None, description="When data was last successfully synced"
    )
    syncFromDate: Optional[datetime] = Field(
        default=None, description="Don't fetch data older than this date"
    )

    # Sharing
    sharedWithPractitioners: bool = Field(
        default=True, description="Whether device data is shared with the patient's practitioners"
    )

    # Companion app device info (model, manufacturer, OS, etc.)
    metadata: dict = Field(
        default_factory=dict,
        description="Companion app device info (model, manufacturer, OS version, source)"
    )
