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 ..models.legacytypes_plan_admin_status_enum import LegacytypesPlanAdminStatusEnum
from ..models.legacytypes_plan_admin_status_enum_description import LegacytypesPlanAdminStatusEnumDescription
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.legacytypes_plan_admin_status_history import LegacytypesPlanAdminStatusHistory


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


@_attrs_define
class LegacytypesPlanAdminStatus:
    """
    Attributes:
        field_id (str | Unset):
        calculated_status (LegacytypesPlanAdminStatusEnum | Unset):
        census_error_count (int | Unset):
        created_at (str | Unset):
        deleted_at (str | Unset):
        description (LegacytypesPlanAdminStatusEnumDescription | Unset):
        employee_error_count (int | Unset):
        history (list[LegacytypesPlanAdminStatusHistory] | Unset):
        is_override (bool | Unset):
        plan (str | Unset):
        plan_year (int | Unset):
        status (LegacytypesPlanAdminStatusEnum | Unset):
        team (str | Unset):
        timestamp (str | Unset):
    """

    field_id: str | Unset = UNSET
    calculated_status: LegacytypesPlanAdminStatusEnum | Unset = UNSET
    census_error_count: int | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    description: LegacytypesPlanAdminStatusEnumDescription | Unset = UNSET
    employee_error_count: int | Unset = UNSET
    history: list[LegacytypesPlanAdminStatusHistory] | Unset = UNSET
    is_override: bool | Unset = UNSET
    plan: str | Unset = UNSET
    plan_year: int | Unset = UNSET
    status: LegacytypesPlanAdminStatusEnum | Unset = UNSET
    team: str | Unset = UNSET
    timestamp: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        calculated_status: str | Unset = UNSET
        if not isinstance(self.calculated_status, Unset):
            calculated_status = self.calculated_status.value

        census_error_count = self.census_error_count

        created_at = self.created_at

        deleted_at = self.deleted_at

        description: str | Unset = UNSET
        if not isinstance(self.description, Unset):
            description = self.description.value

        employee_error_count = self.employee_error_count

        history: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.history, Unset):
            history = []
            for history_item_data in self.history:
                history_item = history_item_data.to_dict()
                history.append(history_item)

        is_override = self.is_override

        plan = self.plan

        plan_year = self.plan_year

        status: str | Unset = UNSET
        if not isinstance(self.status, Unset):
            status = self.status.value

        team = self.team

        timestamp = self.timestamp

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if calculated_status is not UNSET:
            field_dict["calculated_status"] = calculated_status
        if census_error_count is not UNSET:
            field_dict["census_error_count"] = census_error_count
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if description is not UNSET:
            field_dict["description"] = description
        if employee_error_count is not UNSET:
            field_dict["employee_error_count"] = employee_error_count
        if history is not UNSET:
            field_dict["history"] = history
        if is_override is not UNSET:
            field_dict["is_override"] = is_override
        if plan is not UNSET:
            field_dict["plan"] = plan
        if plan_year is not UNSET:
            field_dict["plan_year"] = plan_year
        if status is not UNSET:
            field_dict["status"] = status
        if team is not UNSET:
            field_dict["team"] = team
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.legacytypes_plan_admin_status_history import LegacytypesPlanAdminStatusHistory

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        _calculated_status = d.pop("calculated_status", UNSET)
        calculated_status: LegacytypesPlanAdminStatusEnum | Unset
        if isinstance(_calculated_status, Unset):
            calculated_status = UNSET
        else:
            calculated_status = LegacytypesPlanAdminStatusEnum(_calculated_status)

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

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

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

        _description = d.pop("description", UNSET)
        description: LegacytypesPlanAdminStatusEnumDescription | Unset
        if isinstance(_description, Unset):
            description = UNSET
        else:
            description = LegacytypesPlanAdminStatusEnumDescription(_description)

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

        _history = d.pop("history", UNSET)
        history: list[LegacytypesPlanAdminStatusHistory] | Unset = UNSET
        if _history is not UNSET:
            history = []
            for history_item_data in _history:
                history_item = LegacytypesPlanAdminStatusHistory.from_dict(history_item_data)

                history.append(history_item)

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

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

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

        _status = d.pop("status", UNSET)
        status: LegacytypesPlanAdminStatusEnum | Unset
        if isinstance(_status, Unset):
            status = UNSET
        else:
            status = LegacytypesPlanAdminStatusEnum(_status)

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

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

        legacytypes_plan_admin_status = cls(
            field_id=field_id,
            calculated_status=calculated_status,
            census_error_count=census_error_count,
            created_at=created_at,
            deleted_at=deleted_at,
            description=description,
            employee_error_count=employee_error_count,
            history=history,
            is_override=is_override,
            plan=plan,
            plan_year=plan_year,
            status=status,
            team=team,
            timestamp=timestamp,
        )

        legacytypes_plan_admin_status.additional_properties = d
        return legacytypes_plan_admin_status

    @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
