from __future__ import annotations

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

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

from ..types import UNSET, Unset

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


@_attrs_define
class CwsErrorDTO:
    """
    Attributes:
        correlation_id (str | Unset): The Correlation ID to track the request through all systems where it has been
            processed. Example: b011a094-fade-11e7-8c3f-9a214cf093ae.
        messages (list[str] | Unset): A list of messages. Any single error is described within a certain message.
    """

    correlation_id: str | Unset = UNSET
    messages: list[str] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        messages: list[str] | Unset = UNSET
        if not isinstance(self.messages, Unset):
            messages = self.messages

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if correlation_id is not UNSET:
            field_dict["correlationId"] = correlation_id
        if messages is not UNSET:
            field_dict["messages"] = messages

        return field_dict

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

        messages = cast(list[str], d.pop("messages", UNSET))

        cws_error_dto = cls(
            correlation_id=correlation_id,
            messages=messages,
        )

        cws_error_dto.additional_properties = d
        return cws_error_dto

    @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
