"""
Manual health log models for user-entered data.

Tracks diet, alcohol, supplements, and body feelings.
"""

from __future__ import annotations

from datetime import date, datetime
from typing import Optional, List
from pydantic import BaseModel, Field, ConfigDict


class DietEntry(BaseModel):
    """Single diet entry for a meal or snack."""

    time: str = Field(..., description="Time of meal (HH:MM format)")
    description: str = Field(..., description="What was eaten")
    meal_type: Optional[str] = Field(None, description="breakfast/lunch/dinner/snack")
    estimated_calories: Optional[int] = Field(None, description="Estimated calories")
    carbs: Optional[str] = Field(None, description="Low/Medium/High carb content")
    notes: Optional[str] = Field(None, description="Additional notes")


class AlcoholEntry(BaseModel):
    """Alcohol consumption entry."""

    time: str = Field(..., description="Time of consumption (HH:MM format)")
    drink_type: str = Field(..., description="Type of alcohol (wine/spirits/beer/cocktail)")
    amount: str = Field(..., description="Amount consumed (e.g., '2 glasses', '3 shots')")
    food_with_alcohol: Optional[str] = Field(None, description="What food was eaten")
    nac_taken: bool = Field(False, description="Whether NAC was taken pre-drinking")
    notes: Optional[str] = Field(None, description="Additional notes")


class SupplementEntry(BaseModel):
    """Supplement intake entry."""

    time: str = Field(..., description="Time taken (HH:MM format)")
    supplement_name: str = Field(..., description="Name of supplement")
    dosage: Optional[str] = Field(None, description="Dosage taken")
    timing: Optional[str] = Field(None, description="morning/afternoon/evening/before_bed")
    notes: Optional[str] = Field(None, description="Additional notes")


class BodyFeelingEntry(BaseModel):
    """Body feeling and symptom entry."""

    time: str = Field(..., description="Time recorded (HH:MM format)")
    feeling_type: str = Field(
        ...,
        description="Type of feeling (chest_tightness/fatigue/pain/energy/other)"
    )
    severity: Optional[int] = Field(
        None,
        ge=1,
        le=10,
        description="Severity 1-10"
    )
    location: Optional[str] = Field(None, description="Body location if applicable")
    description: str = Field(..., description="Detailed description")
    triggers: Optional[str] = Field(None, description="Possible triggers")
    notes: Optional[str] = Field(None, description="Additional notes")


class DailyManualLog(BaseModel):
    """Complete manual log for a single day."""

    log_date: date = Field(..., description="Date of the log")
    fasting_mode: Optional[str] = Field(
        None,
        description="PSMF/OMAD/Water Fast/Normal"
    )
    diet_entries: List[DietEntry] = Field(default_factory=list)
    alcohol_entries: List[AlcoholEntry] = Field(default_factory=list)
    supplement_entries: List[SupplementEntry] = Field(default_factory=list)
    feeling_entries: List[BodyFeelingEntry] = Field(default_factory=list)

    daily_summary: Optional[str] = Field(
        None,
        description="Overall summary of the day"
    )
    created_at: datetime = Field(default_factory=datetime.now)
    updated_at: datetime = Field(default_factory=datetime.now)

    model_config = ConfigDict(
        json_encoders={
            date: lambda v: v.isoformat(),
            datetime: lambda v: v.isoformat(),
        }
    )
