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


class RecolteCreate(SQLModel):
    quantite: float
    unite: str = "kg"  # kg|g|unites|litres|bottes
    date_recolte: date
    notes: Optional[str] = None


class Recolte(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    plantation_id: int = Field(foreign_key="planting.id", index=True)
    quantite: float
    unite: str = "kg"
    date_recolte: date
    notes: Optional[str] = None
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))


class ObservationCreate(SQLModel):
    type: str  # maladie|ravageur|traitement|note
    titre: str
    description: Optional[str] = None
    date: date
    photo_url: Optional[str] = None
    plantation_id: Optional[int] = None
    garden_id: Optional[int] = None


class Observation(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    type: str
    titre: str
    description: Optional[str] = None
    date: date
    photo_url: Optional[str] = None
    plantation_id: Optional[int] = Field(default=None, foreign_key="planting.id")
    garden_id: Optional[int] = Field(default=None, foreign_key="garden.id")
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
