from __future__ import annotations

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

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_provision import TypesProvision
    from ..models.types_retirement_plan import TypesRetirementPlan


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


@_attrs_define
class PkgRoutesPackagesRetirementFormatsImportProvisionsResponse:
    """
    Attributes:
        plan (TypesRetirementPlan | Unset):
        provisions (list[TypesProvision] | Unset):
        success (bool | Unset):
    """

    plan: TypesRetirementPlan | Unset = UNSET
    provisions: list[TypesProvision] | Unset = UNSET
    success: bool | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        provisions: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.provisions, Unset):
            provisions = []
            for provisions_item_data in self.provisions:
                provisions_item = provisions_item_data.to_dict()
                provisions.append(provisions_item)

        success = self.success

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if plan is not UNSET:
            field_dict["plan"] = plan
        if provisions is not UNSET:
            field_dict["provisions"] = provisions
        if success is not UNSET:
            field_dict["success"] = success

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_provision import TypesProvision
        from ..models.types_retirement_plan import TypesRetirementPlan

        d = dict(src_dict)
        _plan = d.pop("plan", UNSET)
        plan: TypesRetirementPlan | Unset
        if isinstance(_plan, Unset):
            plan = UNSET
        else:
            plan = TypesRetirementPlan.from_dict(_plan)

        _provisions = d.pop("provisions", UNSET)
        provisions: list[TypesProvision] | Unset = UNSET
        if _provisions is not UNSET:
            provisions = []
            for provisions_item_data in _provisions:
                provisions_item = TypesProvision.from_dict(provisions_item_data)

                provisions.append(provisions_item)

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

        pkg_routes_packages_retirement_formats_import_provisions_response = cls(
            plan=plan,
            provisions=provisions,
            success=success,
        )

        pkg_routes_packages_retirement_formats_import_provisions_response.additional_properties = d
        return pkg_routes_packages_retirement_formats_import_provisions_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
