from __future__ import annotations

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

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.pkg_routes_packages_retirement_participants_batch_update_request_census_item import (
        PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestCensusItem,
    )
    from ..models.pkg_routes_packages_retirement_participants_batch_update_request_insert_item import (
        PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestInsertItem,
    )
    from ..models.pkg_routes_packages_retirement_participants_batch_update_request_upsert_item import (
        PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestUpsertItem,
    )


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


@_attrs_define
class PkgRoutesPackagesRetirementParticipantsBatchUpdateRequest:
    """
    Attributes:
        census (list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestCensusItem] | Unset): List of employee
            census data to update (must include plan year)
            All employees here MUST exist in the system or in the insert list - references to employees are by SSN here, not
            employee ID
        delete (list[str] | Unset): List of employee IDs to delete
        insert (list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestInsertItem] | Unset): List of new
            employees to add
        plan_year (int | Unset):
        upsert (list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestUpsertItem] | Unset): List of employees to
            update
    """

    census: list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestCensusItem] | Unset = UNSET
    delete: list[str] | Unset = UNSET
    insert: list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestInsertItem] | Unset = UNSET
    plan_year: int | Unset = UNSET
    upsert: list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestUpsertItem] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        census: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.census, Unset):
            census = []
            for census_item_data in self.census:
                census_item = census_item_data.to_dict()
                census.append(census_item)

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

        insert: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.insert, Unset):
            insert = []
            for insert_item_data in self.insert:
                insert_item = insert_item_data.to_dict()
                insert.append(insert_item)

        plan_year = self.plan_year

        upsert: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.upsert, Unset):
            upsert = []
            for upsert_item_data in self.upsert:
                upsert_item = upsert_item_data.to_dict()
                upsert.append(upsert_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if census is not UNSET:
            field_dict["census"] = census
        if delete is not UNSET:
            field_dict["delete"] = delete
        if insert is not UNSET:
            field_dict["insert"] = insert
        if plan_year is not UNSET:
            field_dict["plan_year"] = plan_year
        if upsert is not UNSET:
            field_dict["upsert"] = upsert

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.pkg_routes_packages_retirement_participants_batch_update_request_census_item import (
            PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestCensusItem,
        )
        from ..models.pkg_routes_packages_retirement_participants_batch_update_request_insert_item import (
            PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestInsertItem,
        )
        from ..models.pkg_routes_packages_retirement_participants_batch_update_request_upsert_item import (
            PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestUpsertItem,
        )

        d = dict(src_dict)
        _census = d.pop("census", UNSET)
        census: list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestCensusItem] | Unset = UNSET
        if _census is not UNSET:
            census = []
            for census_item_data in _census:
                census_item = PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestCensusItem.from_dict(
                    census_item_data
                )

                census.append(census_item)

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

        _insert = d.pop("insert", UNSET)
        insert: list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestInsertItem] | Unset = UNSET
        if _insert is not UNSET:
            insert = []
            for insert_item_data in _insert:
                insert_item = PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestInsertItem.from_dict(
                    insert_item_data
                )

                insert.append(insert_item)

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

        _upsert = d.pop("upsert", UNSET)
        upsert: list[PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestUpsertItem] | Unset = UNSET
        if _upsert is not UNSET:
            upsert = []
            for upsert_item_data in _upsert:
                upsert_item = PkgRoutesPackagesRetirementParticipantsBatchUpdateRequestUpsertItem.from_dict(
                    upsert_item_data
                )

                upsert.append(upsert_item)

        pkg_routes_packages_retirement_participants_batch_update_request = cls(
            census=census,
            delete=delete,
            insert=insert,
            plan_year=plan_year,
            upsert=upsert,
        )

        pkg_routes_packages_retirement_participants_batch_update_request.additional_properties = d
        return pkg_routes_packages_retirement_participants_batch_update_request

    @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
