from __future__ import annotations

import datetime
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 dateutil.parser import isoparse

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.note import Note
    from ..models.tpa_account_status import TpaAccountStatus
    from ..models.tpa_account_viewed import TpaAccountViewed


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


@_attrs_define
class TpaAccount:
    """
    Attributes:
        field_id (str | Unset): MongoDB ObjectId
        team (str | Unset): MongoDB ObjectId
        plan_id (str | Unset): MongoDB ObjectId
        account_type (str | Unset):
        pension_pro_id (float | Unset):
        internal_plan_id (str | Unset):
        provider (str | Unset):
        number (str | Unset):
        payee (str | Unset):
        active (bool | Unset):
        pp_lock (bool | Unset):
        notes (list[Note] | Unset):
        last_modified (datetime.datetime | Unset):
        type_ (str | Unset):
        status (TpaAccountStatus | Unset):
        viewed (TpaAccountViewed | Unset):
    """

    field_id: str | Unset = UNSET
    team: str | Unset = UNSET
    plan_id: str | Unset = UNSET
    account_type: str | Unset = UNSET
    pension_pro_id: float | Unset = UNSET
    internal_plan_id: str | Unset = UNSET
    provider: str | Unset = UNSET
    number: str | Unset = UNSET
    payee: str | Unset = UNSET
    active: bool | Unset = UNSET
    pp_lock: bool | Unset = UNSET
    notes: list[Note] | Unset = UNSET
    last_modified: datetime.datetime | Unset = UNSET
    type_: str | Unset = UNSET
    status: TpaAccountStatus | Unset = UNSET
    viewed: TpaAccountViewed | 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

        team = self.team

        plan_id = self.plan_id

        account_type = self.account_type

        pension_pro_id = self.pension_pro_id

        internal_plan_id = self.internal_plan_id

        provider = self.provider

        number = self.number

        payee = self.payee

        active = self.active

        pp_lock = self.pp_lock

        notes: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.notes, Unset):
            notes = []
            for notes_item_data in self.notes:
                notes_item = notes_item_data.to_dict()
                notes.append(notes_item)

        last_modified: str | Unset = UNSET
        if not isinstance(self.last_modified, Unset):
            last_modified = self.last_modified.isoformat()

        type_ = self.type_

        status: dict[str, Any] | Unset = UNSET
        if not isinstance(self.status, Unset):
            status = self.status.to_dict()

        viewed: dict[str, Any] | Unset = UNSET
        if not isinstance(self.viewed, Unset):
            viewed = self.viewed.to_dict()

        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 team is not UNSET:
            field_dict["team"] = team
        if plan_id is not UNSET:
            field_dict["planId"] = plan_id
        if account_type is not UNSET:
            field_dict["accountType"] = account_type
        if pension_pro_id is not UNSET:
            field_dict["pensionProId"] = pension_pro_id
        if internal_plan_id is not UNSET:
            field_dict["internalPlanId"] = internal_plan_id
        if provider is not UNSET:
            field_dict["provider"] = provider
        if number is not UNSET:
            field_dict["number"] = number
        if payee is not UNSET:
            field_dict["payee"] = payee
        if active is not UNSET:
            field_dict["active"] = active
        if pp_lock is not UNSET:
            field_dict["ppLock"] = pp_lock
        if notes is not UNSET:
            field_dict["notes"] = notes
        if last_modified is not UNSET:
            field_dict["lastModified"] = last_modified
        if type_ is not UNSET:
            field_dict["type"] = type_
        if status is not UNSET:
            field_dict["status"] = status
        if viewed is not UNSET:
            field_dict["viewed"] = viewed

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.note import Note
        from ..models.tpa_account_status import TpaAccountStatus
        from ..models.tpa_account_viewed import TpaAccountViewed

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

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

        plan_id = d.pop("planId", UNSET)

        account_type = d.pop("accountType", UNSET)

        pension_pro_id = d.pop("pensionProId", UNSET)

        internal_plan_id = d.pop("internalPlanId", UNSET)

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

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

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

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

        pp_lock = d.pop("ppLock", UNSET)

        _notes = d.pop("notes", UNSET)
        notes: list[Note] | Unset = UNSET
        if _notes is not UNSET:
            notes = []
            for notes_item_data in _notes:
                notes_item = Note.from_dict(notes_item_data)

                notes.append(notes_item)

        _last_modified = d.pop("lastModified", UNSET)
        last_modified: datetime.datetime | Unset
        if isinstance(_last_modified, Unset):
            last_modified = UNSET
        else:
            last_modified = isoparse(_last_modified)

        type_ = d.pop("type", UNSET)

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

        _viewed = d.pop("viewed", UNSET)
        viewed: TpaAccountViewed | Unset
        if isinstance(_viewed, Unset):
            viewed = UNSET
        else:
            viewed = TpaAccountViewed.from_dict(_viewed)

        tpa_account = cls(
            field_id=field_id,
            team=team,
            plan_id=plan_id,
            account_type=account_type,
            pension_pro_id=pension_pro_id,
            internal_plan_id=internal_plan_id,
            provider=provider,
            number=number,
            payee=payee,
            active=active,
            pp_lock=pp_lock,
            notes=notes,
            last_modified=last_modified,
            type_=type_,
            status=status,
            viewed=viewed,
        )

        tpa_account.additional_properties = d
        return tpa_account

    @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
