import datetime
from typing import TYPE_CHECKING, Any, TypeVar, Union

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from attrs import fields as _attrs_fields
from dateutil.parser import isoparse

from ..types import UNSET, OSIDBModel, Unset

if TYPE_CHECKING:
    from ..models.exploits_api_v2_report_explanations_retrieve_response_200_explanations_item import (
        ExploitsApiV2ReportExplanationsRetrieveResponse200ExplanationsItem,
    )


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


@_attrs_define
class ExploitsApiV2ReportExplanationsRetrieveResponse200(OSIDBModel):
    """
    Attributes:
        dt (Union[Unset, datetime.datetime]):
        env (Union[Unset, str]):
        explanations (Union[Unset, list['ExploitsApiV2ReportExplanationsRetrieveResponse200ExplanationsItem']]):
        page_size (Union[Unset, int]):
        revision (Union[Unset, str]):
        version (Union[Unset, str]):
    """

    dt: Union[Unset, datetime.datetime] = UNSET
    env: Union[Unset, str] = UNSET
    explanations: Union[
        Unset,
        list["ExploitsApiV2ReportExplanationsRetrieveResponse200ExplanationsItem"],
    ] = UNSET
    page_size: Union[Unset, int] = UNSET
    revision: Union[Unset, str] = UNSET
    version: Union[Unset, str] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        dt: Union[Unset, str] = UNSET
        if not isinstance(self.dt, Unset):
            dt = self.dt.isoformat()

        env = self.env

        explanations: Union[Unset, list[dict[str, Any]]] = UNSET
        if not isinstance(self.explanations, Unset):
            explanations = []
            for explanations_item_data in self.explanations:
                explanations_item: dict[str, Any] = UNSET
                if not isinstance(explanations_item_data, Unset):
                    explanations_item = explanations_item_data.to_dict()

                explanations.append(explanations_item)

        page_size = self.page_size

        revision = self.revision

        version = self.version

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        if not isinstance(dt, Unset):
            field_dict["dt"] = dt
        if not isinstance(env, Unset):
            field_dict["env"] = env
        if not isinstance(explanations, Unset):
            field_dict["explanations"] = explanations
        if not isinstance(page_size, Unset):
            field_dict["page_size"] = page_size
        if not isinstance(revision, Unset):
            field_dict["revision"] = revision
        if not isinstance(version, Unset):
            field_dict["version"] = version

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
        from ..models.exploits_api_v2_report_explanations_retrieve_response_200_explanations_item import (
            ExploitsApiV2ReportExplanationsRetrieveResponse200ExplanationsItem,
        )

        d = src_dict.copy()
        _dt = d.pop("dt", UNSET)
        dt: Union[Unset, datetime.datetime]
        if isinstance(_dt, Unset):
            dt = UNSET
        else:
            dt = isoparse(_dt)

        env = d.pop("env", UNSET)

        explanations = []
        _explanations = d.pop("explanations", UNSET)
        for explanations_item_data in _explanations or []:
            _explanations_item = explanations_item_data
            explanations_item: (
                ExploitsApiV2ReportExplanationsRetrieveResponse200ExplanationsItem
            )
            if isinstance(_explanations_item, Unset):
                explanations_item = UNSET
            else:
                explanations_item = ExploitsApiV2ReportExplanationsRetrieveResponse200ExplanationsItem.from_dict(
                    _explanations_item
                )

            explanations.append(explanations_item)

        page_size = d.pop("page_size", UNSET)

        revision = d.pop("revision", UNSET)

        version = d.pop("version", UNSET)

        exploits_api_v2_report_explanations_retrieve_response_200 = cls(
            dt=dt,
            env=env,
            explanations=explanations,
            page_size=page_size,
            revision=revision,
            version=version,
        )

        exploits_api_v2_report_explanations_retrieve_response_200.additional_properties = d
        return exploits_api_v2_report_explanations_retrieve_response_200

    @classmethod
    def get_fields(cls):
        return {f.name: f.type for f in _attrs_fields(cls)}

    @classmethod
    def new(cls):
        return cls.from_dict({})

    @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
