from __future__ import annotations

from http import HTTPStatus

from pydantic import BaseModel


class ProblemDetails(BaseModel):
    type: str = "about:blank"
    title: str
    status: int
    detail: str
    instance: str | None = None


def build_problem_details(
    *,
    status_code: int,
    detail: str,
    type_value: str = "about:blank",
    title: str | None = None,
    instance: str | None = None,
) -> ProblemDetails:
    resolved_title = title or HTTPStatus(status_code).phrase
    return ProblemDetails(
        type=type_value,
        title=resolved_title,
        status=status_code,
        detail=detail,
        instance=instance,
    )
