from __future__ import annotations from typing import Optional from uuid import UUID from pydantic import BaseModel, Field, model_validator class NeverSuggestCreate(BaseModel): family_profile_id: UUID ingredient_id: Optional[UUID] = None recipe_id: Optional[UUID] = None reason: Optional[str] = Field(default=None, max_length=50) notes: Optional[str] = None @model_validator(mode="after") def _exactly_one_target(self) -> "NeverSuggestCreate": present = sum(x is not None for x in (self.ingredient_id, self.recipe_id)) if present != 1: raise ValueError("exactly one of ingredient_id or recipe_id must be set") return self class NeverSuggestRead(BaseModel): id: UUID family_profile_id: UUID ingredient_id: Optional[UUID] = None recipe_id: Optional[UUID] = None reason: Optional[str] = None notes: Optional[str] = None # Server-side joins. Populated by the router via a single LEFT OUTER # JOIN to recipe / ingredient; falls back to None when the target # row has been deleted (the FK is ON DELETE CASCADE so the # NeverSuggest row goes with it; this is belt-and-suspenders for # the rare in-flight case). recipe_name: Optional[str] = None ingredient_name: Optional[str] = None model_config = {"from_attributes": True}