"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from dataclasses import dataclass, field
import httpx
from postivo_client.errors import ClientError
from postivo_client.types import BaseModel
from typing import Optional


class ErrorResponseData(BaseModel):
    type: Optional[str] = None
    r"""URI that identifies the problem type."""

    status: Optional[int] = None
    r"""HTTP status code generated by the origin server for this occurrence of the problem."""

    title: Optional[str] = None
    r"""Short, human-readable summary of the problem type."""

    detail: Optional[str] = None
    r"""Human-readable explanation specific to this occurrence of the problem."""

    code: Optional[str] = None
    r"""API-specific error code to help the provider team classify the error."""

    instance: Optional[str] = None
    r"""URI that identifies this specific occurrence of the problem."""


@dataclass(unsafe_hash=True)
class ErrorResponse(ClientError):
    r"""Problem Details object (RFC 9457) describing the error."""

    data: ErrorResponseData = field(hash=False)

    def __init__(
        self,
        data: ErrorResponseData,
        raw_response: httpx.Response,
        body: Optional[str] = None,
    ):
        fallback = body or raw_response.text
        message = str(data.detail) or fallback
        super().__init__(message, raw_response, body)
        object.__setattr__(self, "data", data)
