from typing import Optional
from sqlmodel import Field, SQLModel


class MeteoStation(SQLModel, table=True):
    """Données collectées depuis la station WeeWX locale."""
    __tablename__ = "meteostation"

    date_heure: str = Field(primary_key=True)  # "2026-02-22T14:00"
    type: str = "current"  # "current" | "veille"
    temp_ext: Optional[float] = None   # °C extérieur
    temp_int: Optional[float] = None   # °C intérieur (serre)
    humidite: Optional[float] = None   # %
    pression: Optional[float] = None   # hPa
    pluie_mm: Optional[float] = None   # précipitations
    vent_kmh: Optional[float] = None
    vent_dir: Optional[str] = None     # N/NE/E/SE/S/SO/O/NO
    uv: Optional[float] = None
    solaire: Optional[float] = None    # W/m²


class MeteoOpenMeteo(SQLModel, table=True):
    """Prévisions journalières Open-Meteo."""
    __tablename__ = "meteoopenmeteo"

    date: str = Field(primary_key=True)  # "2026-02-22"
    t_min: Optional[float] = None
    t_max: Optional[float] = None
    pluie_mm: Optional[float] = None
    vent_kmh: Optional[float] = None
    wmo: Optional[int] = None
    label: Optional[str] = None
    humidite_moy: Optional[float] = None
    sol_0cm: Optional[float] = None    # temp sol surface
    etp_mm: Optional[float] = None     # évapotranspiration
    fetched_at: Optional[str] = None
