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

from __future__ import annotations
from dataclasses import dataclass, field
import httpx
from outpost_sdk.errors import OutpostError
from outpost_sdk.types import BaseModel
from typing import Any, Dict, List, Optional, Union
from typing_extensions import TypeAliasType


DataTypedDict = TypeAliasType("DataTypedDict", Union[List[str], Dict[str, Any]])
r"""Additional error details. For validation errors, this is an array of human-readable messages."""


Data = TypeAliasType("Data", Union[List[str], Dict[str, Any]])
r"""Additional error details. For validation errors, this is an array of human-readable messages."""


class APIErrorResponseData(BaseModel):
    status: Optional[int] = None
    r"""HTTP status code."""
    message: Optional[str] = None
    r"""Human-readable error message."""
    data: Optional[Data] = None
    r"""Additional error details. For validation errors, this is an array of human-readable messages."""


@dataclass(unsafe_hash=True)
class APIErrorResponse(OutpostError):
    r"""Standard error response format."""

    data: APIErrorResponseData = field(hash=False)

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