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


class Astuce(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    # Anciens champs conservés (colonnes existantes en DB)
    entity_type: Optional[str] = None
    entity_id: Optional[int] = None
    source: Optional[str] = None
    # Champs principaux
    titre: str
    contenu: str
    # Nouveaux champs bibliothèque
    categorie: Optional[str] = None   # "plante"|"jardin"|"tache"|"general"|"ravageur"|"maladie"
    tags: Optional[str] = None        # JSON array string: '["tomate","semis"]'
    mois: Optional[str] = None        # JSON array string: '[3,4,5]' ou null = toute l'année
    created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
