from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

T = TypeVar("T", bound="RouterErrorResponse")


@_attrs_define
class RouterErrorResponse:
    """Response in case of error

    Attributes:
        action (str): Human-readable description of the action that can be taken to correct the error Example: Request a
            valid id.
        cause (str): Human-readable explanation for the error Example: The input data in question does not comply with
            validation rules.
        code (str): Error code.

            All error codes start with "`E60`".
             Example: E600101.
        correlation_id (str): Auto-generated id that univocally identifies the request Example:
            4199533b-6290-41db-8d79-edf4f4019a74.
        status (int): HTTP status code Example: 400.
        title (str): Human-readable error description Example: Input data failed validation.
    """

    action: str
    cause: str
    code: str
    correlation_id: str
    status: int
    title: str
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        action = self.action

        cause = self.cause

        code = self.code

        correlation_id = self.correlation_id

        status = self.status

        title = self.title

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "action": action,
            "cause": cause,
            "code": code,
            "correlationId": correlation_id,
            "status": status,
            "title": title,
        })

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        action = d.pop("action")

        cause = d.pop("cause")

        code = d.pop("code")

        correlation_id = d.pop("correlationId")

        status = d.pop("status")

        title = d.pop("title")

        router_error_response = cls(
            action=action,
            cause=cause,
            code=code,
            correlation_id=correlation_id,
            status=status,
            title=title,
        )

        router_error_response.additional_properties = d
        return router_error_response

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
