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


class Plant(SQLModel, table=True):
    __tablename__ = "plant"

    id: Optional[int] = Field(default=None, primary_key=True)
    nom_commun: str
    nom_botanique: Optional[str] = None
    variete: Optional[str] = None
    famille: Optional[str] = None
    tags: Optional[str] = None  # CSV
    type_plante: Optional[str] = None  # legume | fruit | aromatique | fleur
    categorie: Optional[str] = None  # potager|fleur|arbre|arbuste
    besoin_eau: Optional[str] = None  # faible | moyen | fort
    besoin_soleil: Optional[str] = None
    espacement_cm: Optional[int] = None
    hauteur_cm: Optional[int] = None
    temp_min_c: Optional[float] = None
    duree_culture_j: Optional[int] = None
    profondeur_semis_cm: Optional[float] = None
    sol_conseille: Optional[str] = None
    semis_interieur_mois: Optional[str] = None  # ex: "2,3"
    semis_exterieur_mois: Optional[str] = None
    repiquage_mois: Optional[str] = None
    plantation_mois: Optional[str] = None
    recolte_mois: Optional[str] = None
    maladies_courantes: Optional[str] = None
    astuces_culture: Optional[str] = None
    url_reference: Optional[str] = None
    notes: Optional[str] = None
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))


class PlantImage(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    plant_id: int = Field(foreign_key="plant.id", index=True)
    filename: str
    caption: Optional[str] = None
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
