"""Simulation plan schemas."""
from datetime import datetime
from typing import Optional, Any
from pydantic import BaseModel, Field


class PlanCreate(BaseModel):
    project_id: int
    name: str = Field(..., min_length=1, max_length=200)
    plan_data: dict[str, Any] = Field(..., description="Full simulation_plan.json content")
    notes: str = ""


class PlanUpdate(BaseModel):
    name: Optional[str] = None
    status: Optional[str] = None
    plan_data: Optional[dict[str, Any]] = None
    notes: Optional[str] = None


class PlanResponse(BaseModel):
    id: int
    project_id: int
    name: str
    plan_id: str
    status: str
    plan_data: dict[str, Any]
    variables_summary: dict[str, Any] = Field(default_factory=dict)
    estimated_points: int = 0
    estimated_time_min: int = 0
    notes: str
    result_count: int = 0
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class PlanListResponse(BaseModel):
    total: int
    items: list[PlanResponse]


class PlanDownloadResponse(BaseModel):
    """Response for plan download - returns raw JSON compatible with local executor."""
    plan_id: str
    plan_data: dict[str, Any]
