"""
Schemas for crop plans (saved planning scenarios) and notifications
(in-app/email alerts) — the data the SaaS dashboard reads and writes
beyond the core analysis flow.
"""

from pydantic import BaseModel, Field


class CropPlanCreateRequest(BaseModel):
    name: str = Field(..., min_length=1, max_length=255)
    crop: str = Field(..., min_length=2, max_length=50)
    location: str = Field(..., min_length=2, max_length=100)
    planting_month: int = Field(..., ge=1, le=12)
    risk_tolerance: str = Field("moderate", pattern="^(low|moderate|high)$")


class CropPlanUpdateRequest(BaseModel):
    name: str | None = Field(None, min_length=1, max_length=255)
    risk_tolerance: str | None = Field(None, pattern="^(low|moderate|high)$")
    is_archived: bool | None = None


class CropPlanResponse(BaseModel):
    id: str
    name: str
    crop: str
    location: str
    planting_month: int
    risk_tolerance: str
    is_archived: bool
    created_at: str
    updated_at: str
    latest_feasibility_label: str | None = None
    latest_analysis_at: str | None = None


class NotificationResponse(BaseModel):
    id: str
    title: str
    message: str
    severity: str
    related_crop_plan_id: str | None
    is_read: bool
    created_at: str


class NotificationListResponse(BaseModel):
    notifications: list[NotificationResponse]
    unread_count: int
