from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field


class MixIngredientCreate(BaseModel):
    raw_material_id: int
    quantity_kg: float = Field(gt=0)
    notes: str | None = None


class MixIngredientUpdate(BaseModel):
    quantity_kg: float | None = Field(default=None, gt=0)
    notes: str | None = None


class MixIngredientRead(BaseModel):
    id: int
    raw_material_id: int
    raw_material_name: str
    quantity_kg: float
    cost_per_kg: float | None
    line_cost: float | None
    notes: str | None
    model_config = ConfigDict(from_attributes=True)


class MixCreate(BaseModel):
    client_name: str
    name: str
    status: str = "draft"
    version: int = 1
    notes: str | None = None
    ingredients: list[MixIngredientCreate]


class MixUpdate(BaseModel):
    client_name: str | None = None
    name: str | None = None
    status: str | None = None
    version: int | None = None
    notes: str | None = None


class MixRead(BaseModel):
    id: int
    tenant_id: str
    client_name: str
    name: str
    status: str
    version: int
    notes: str | None
    created_at: datetime
    ingredients: list[MixIngredientRead]
    total_mix_kg: float
    total_mix_cost: float
    mix_cost_per_kg: float | None
    warnings: list[str]
    model_config = ConfigDict(from_attributes=True)

