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

from __future__ import annotations
from dataclasses import dataclass, field
import httpx
from opperai.errors import OpperError
from opperai.types import BaseModel
from typing import Any, Optional


class UnauthorizedErrorData(BaseModel):
    detail: Any
    r"""The detail of the error"""

    type: Optional[str] = "UnauthorizedError"

    message: Optional[str] = "The request is unauthorized"


@dataclass(unsafe_hash=True)
class UnauthorizedError(OpperError):
    data: UnauthorizedErrorData = field(hash=False)

    def __init__(
        self,
        data: UnauthorizedErrorData,
        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)
