"""Prompt fetch request model."""

from __future__ import annotations

from pydantic import BaseModel, Field, JsonValue, field_validator

from dr_langfuse.validation import validate_json_safe_dict


class PromptFetchRequest(BaseModel):
    """Request contract for fetching a prompt from Langfuse."""

    prompt_name: str = Field(min_length=1)
    label: str | None = None
    version: int | None = None
    variables: dict[str, JsonValue] = Field(default_factory=dict)

    @field_validator("variables")
    @classmethod
    def _ensure_json_safe_variables(
        cls, variables: dict[str, JsonValue]
    ) -> dict[str, JsonValue]:
        return validate_json_safe_dict(variables, prefix="variables")
