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


class TaskCreate(SQLModel):
    titre: str
    description: Optional[str] = None
    garden_id: Optional[int] = None
    planting_id: Optional[int] = None
    outil_id: Optional[int] = None
    priorite: str = "normale"  # basse | normale | haute
    echeance: Optional[date] = None
    recurrence: Optional[str] = None
    frequence_jours: Optional[int] = None
    date_prochaine: Optional[date] = None
    statut: str = "a_faire"  # a_faire | en_cours | fait | annule


class Task(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    titre: str
    description: Optional[str] = None
    garden_id: Optional[int] = Field(default=None, foreign_key="garden.id")
    planting_id: Optional[int] = Field(default=None, foreign_key="planting.id")
    outil_id: Optional[int] = Field(default=None, foreign_key="tool.id")
    priorite: str = "normale"
    echeance: Optional[date] = None
    recurrence: Optional[str] = None
    frequence_jours: Optional[int] = None
    date_prochaine: Optional[date] = None
    statut: str = "a_faire"
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
    updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
