from datetime import datetime, timezone
from typing import Optional
from sqlmodel import Field, SQLModel


class Media(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    entity_type: str  # jardin|plante|outil|plantation
    entity_id: int
    url: str
    thumbnail_url: Optional[str] = None
    titre: Optional[str] = None
    # Identification automatique
    identified_species: Optional[str] = None
    identified_common: Optional[str] = None
    identified_confidence: Optional[float] = None
    identified_source: Optional[str] = None  # "plantnet" | "yolo" | "cache"
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))


class Attachment(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    entity_type: str
    entity_id: int
    type: str  # pdf|url|note
    titre: Optional[str] = None
    contenu: Optional[str] = None
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
