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.legacytypes_activity import LegacytypesActivity
    from ..models.legacytypes_assignee_tasks import LegacytypesAssigneeTasks
    from ..models.legacytypes_comment import LegacytypesComment
    from ..models.legacytypes_field import LegacytypesField
    from ..models.legacytypes_investment_account import LegacytypesInvestmentAccount
    from ..models.legacytypes_plan_year_data import LegacytypesPlanYearData
    from ..models.legacytypes_plan_year_project import LegacytypesPlanYearProject
    from ..models.legacytypes_project import LegacytypesProject
    from ..models.legacytypes_provision import LegacytypesProvision
    from ..models.legacytypes_retirement_plan_compliance_status import LegacytypesRetirementPlanComplianceStatus
    from ..models.legacytypes_retirement_plan_rk import LegacytypesRetirementPlanRk
    from ..models.legacytypes_task import LegacytypesTask
    from ..models.legacytypes_transaction_totals import LegacytypesTransactionTotals


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


@_attrs_define
class LegacytypesRetirementPlan:
    """
    Attributes:
        field_id (str | Unset):
        accounts (list[LegacytypesInvestmentAccount] | Unset): Investment accounts
        activity (list[LegacytypesActivity] | Unset): For returning when loading
        assignee_tasks (list[LegacytypesAssigneeTasks] | Unset):
        bond (float | Unset):
        carrier (str | Unset):
        client (str | Unset):
        code (str | Unset):
        comments (list[LegacytypesComment] | Unset):
        compliance_status (LegacytypesRetirementPlanComplianceStatus | Unset): 5500 Status
        created_at (str | Unset):
        data (list[LegacytypesPlanYearData] | Unset):
        deleted_at (str | Unset):
        effective_on (str | Unset):
        employees (int | Unset):
        fields (list[LegacytypesField] | Unset): Custom fields
        ftw_census_grid (str | Unset): Very specific stuff...
        name (str | Unset):
        notes (str | Unset):
        owner_id (str | Unset):
        owner_team (str | Unset): Cross-team collaboration
            When collaborations for clients/plans are accepted, the resources are copied over to the team that accepted the
            collaboration.
            The clients/plans will have unique IDs but will be linked to the original client/plan to maintain a 2-way sync.
        parent_plan (str | Unset): MEPS/PEPS
        participants (int | Unset): Cached data to avoid re-computation
        plan_structure (str | Unset):
        plan_years (list[LegacytypesPlanYearProject] | Unset): Plan year-specific projects to store details
        primary_team_name (str | Unset): If the above properties are nil or omitted, the client/plan is owned by the
            team that created it.
        projects (list[LegacytypesProject] | Unset):
        provisions (list[LegacytypesProvision] | Unset): Provisions
        pye (str | Unset): Plan specifics
        rk (LegacytypesRetirementPlanRk | Unset): Record-keeper
        sequence (int | Unset):
        status (str | Unset):
        tags (list[str] | Unset):
        tasks (list[LegacytypesTask] | Unset):
        team (str | Unset):
        totals (list[LegacytypesTransactionTotals] | Unset):
        tye (str | Unset): Tax Year End
        type_ (str | Unset):
        view (str | Unset):
    """

    field_id: str | Unset = UNSET
    accounts: list[LegacytypesInvestmentAccount] | Unset = UNSET
    activity: list[LegacytypesActivity] | Unset = UNSET
    assignee_tasks: list[LegacytypesAssigneeTasks] | Unset = UNSET
    bond: float | Unset = UNSET
    carrier: str | Unset = UNSET
    client: str | Unset = UNSET
    code: str | Unset = UNSET
    comments: list[LegacytypesComment] | Unset = UNSET
    compliance_status: LegacytypesRetirementPlanComplianceStatus | Unset = UNSET
    created_at: str | Unset = UNSET
    data: list[LegacytypesPlanYearData] | Unset = UNSET
    deleted_at: str | Unset = UNSET
    effective_on: str | Unset = UNSET
    employees: int | Unset = UNSET
    fields: list[LegacytypesField] | Unset = UNSET
    ftw_census_grid: str | Unset = UNSET
    name: str | Unset = UNSET
    notes: str | Unset = UNSET
    owner_id: str | Unset = UNSET
    owner_team: str | Unset = UNSET
    parent_plan: str | Unset = UNSET
    participants: int | Unset = UNSET
    plan_structure: str | Unset = UNSET
    plan_years: list[LegacytypesPlanYearProject] | Unset = UNSET
    primary_team_name: str | Unset = UNSET
    projects: list[LegacytypesProject] | Unset = UNSET
    provisions: list[LegacytypesProvision] | Unset = UNSET
    pye: str | Unset = UNSET
    rk: LegacytypesRetirementPlanRk | Unset = UNSET
    sequence: int | Unset = UNSET
    status: str | Unset = UNSET
    tags: list[str] | Unset = UNSET
    tasks: list[LegacytypesTask] | Unset = UNSET
    team: str | Unset = UNSET
    totals: list[LegacytypesTransactionTotals] | Unset = UNSET
    tye: str | Unset = UNSET
    type_: str | Unset = UNSET
    view: 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

        accounts: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.accounts, Unset):
            accounts = []
            for accounts_item_data in self.accounts:
                accounts_item = accounts_item_data.to_dict()
                accounts.append(accounts_item)

        activity: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.activity, Unset):
            activity = []
            for activity_item_data in self.activity:
                activity_item = activity_item_data.to_dict()
                activity.append(activity_item)

        assignee_tasks: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.assignee_tasks, Unset):
            assignee_tasks = []
            for assignee_tasks_item_data in self.assignee_tasks:
                assignee_tasks_item = assignee_tasks_item_data.to_dict()
                assignee_tasks.append(assignee_tasks_item)

        bond = self.bond

        carrier = self.carrier

        client = self.client

        code = self.code

        comments: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.comments, Unset):
            comments = []
            for comments_item_data in self.comments:
                comments_item = comments_item_data.to_dict()
                comments.append(comments_item)

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

        created_at = self.created_at

        data: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.data, Unset):
            data = []
            for data_item_data in self.data:
                data_item = data_item_data.to_dict()
                data.append(data_item)

        deleted_at = self.deleted_at

        effective_on = self.effective_on

        employees = self.employees

        fields: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.fields, Unset):
            fields = []
            for fields_item_data in self.fields:
                fields_item = fields_item_data.to_dict()
                fields.append(fields_item)

        ftw_census_grid = self.ftw_census_grid

        name = self.name

        notes = self.notes

        owner_id = self.owner_id

        owner_team = self.owner_team

        parent_plan = self.parent_plan

        participants = self.participants

        plan_structure = self.plan_structure

        plan_years: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.plan_years, Unset):
            plan_years = []
            for plan_years_item_data in self.plan_years:
                plan_years_item = plan_years_item_data.to_dict()
                plan_years.append(plan_years_item)

        primary_team_name = self.primary_team_name

        projects: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.projects, Unset):
            projects = []
            for projects_item_data in self.projects:
                projects_item = projects_item_data.to_dict()
                projects.append(projects_item)

        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)

        pye = self.pye

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

        sequence = self.sequence

        status = self.status

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

        tasks: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.tasks, Unset):
            tasks = []
            for tasks_item_data in self.tasks:
                tasks_item = tasks_item_data.to_dict()
                tasks.append(tasks_item)

        team = self.team

        totals: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.totals, Unset):
            totals = []
            for totals_item_data in self.totals:
                totals_item = totals_item_data.to_dict()
                totals.append(totals_item)

        tye = self.tye

        type_ = self.type_

        view = self.view

        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 accounts is not UNSET:
            field_dict["accounts"] = accounts
        if activity is not UNSET:
            field_dict["activity"] = activity
        if assignee_tasks is not UNSET:
            field_dict["assignee_tasks"] = assignee_tasks
        if bond is not UNSET:
            field_dict["bond"] = bond
        if carrier is not UNSET:
            field_dict["carrier"] = carrier
        if client is not UNSET:
            field_dict["client"] = client
        if code is not UNSET:
            field_dict["code"] = code
        if comments is not UNSET:
            field_dict["comments"] = comments
        if compliance_status is not UNSET:
            field_dict["compliance_status"] = compliance_status
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if data is not UNSET:
            field_dict["data"] = data
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if effective_on is not UNSET:
            field_dict["effective_on"] = effective_on
        if employees is not UNSET:
            field_dict["employees"] = employees
        if fields is not UNSET:
            field_dict["fields"] = fields
        if ftw_census_grid is not UNSET:
            field_dict["ftw_census_grid"] = ftw_census_grid
        if name is not UNSET:
            field_dict["name"] = name
        if notes is not UNSET:
            field_dict["notes"] = notes
        if owner_id is not UNSET:
            field_dict["owner_id"] = owner_id
        if owner_team is not UNSET:
            field_dict["owner_team"] = owner_team
        if parent_plan is not UNSET:
            field_dict["parent_plan"] = parent_plan
        if participants is not UNSET:
            field_dict["participants"] = participants
        if plan_structure is not UNSET:
            field_dict["plan_structure"] = plan_structure
        if plan_years is not UNSET:
            field_dict["plan_years"] = plan_years
        if primary_team_name is not UNSET:
            field_dict["primary_team_name"] = primary_team_name
        if projects is not UNSET:
            field_dict["projects"] = projects
        if provisions is not UNSET:
            field_dict["provisions"] = provisions
        if pye is not UNSET:
            field_dict["pye"] = pye
        if rk is not UNSET:
            field_dict["rk"] = rk
        if sequence is not UNSET:
            field_dict["sequence"] = sequence
        if status is not UNSET:
            field_dict["status"] = status
        if tags is not UNSET:
            field_dict["tags"] = tags
        if tasks is not UNSET:
            field_dict["tasks"] = tasks
        if team is not UNSET:
            field_dict["team"] = team
        if totals is not UNSET:
            field_dict["totals"] = totals
        if tye is not UNSET:
            field_dict["tye"] = tye
        if type_ is not UNSET:
            field_dict["type"] = type_
        if view is not UNSET:
            field_dict["view"] = view

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.legacytypes_activity import LegacytypesActivity
        from ..models.legacytypes_assignee_tasks import LegacytypesAssigneeTasks
        from ..models.legacytypes_comment import LegacytypesComment
        from ..models.legacytypes_field import LegacytypesField
        from ..models.legacytypes_investment_account import LegacytypesInvestmentAccount
        from ..models.legacytypes_plan_year_data import LegacytypesPlanYearData
        from ..models.legacytypes_plan_year_project import LegacytypesPlanYearProject
        from ..models.legacytypes_project import LegacytypesProject
        from ..models.legacytypes_provision import LegacytypesProvision
        from ..models.legacytypes_retirement_plan_compliance_status import LegacytypesRetirementPlanComplianceStatus
        from ..models.legacytypes_retirement_plan_rk import LegacytypesRetirementPlanRk
        from ..models.legacytypes_task import LegacytypesTask
        from ..models.legacytypes_transaction_totals import LegacytypesTransactionTotals

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

        _accounts = d.pop("accounts", UNSET)
        accounts: list[LegacytypesInvestmentAccount] | Unset = UNSET
        if _accounts is not UNSET:
            accounts = []
            for accounts_item_data in _accounts:
                accounts_item = LegacytypesInvestmentAccount.from_dict(accounts_item_data)

                accounts.append(accounts_item)

        _activity = d.pop("activity", UNSET)
        activity: list[LegacytypesActivity] | Unset = UNSET
        if _activity is not UNSET:
            activity = []
            for activity_item_data in _activity:
                activity_item = LegacytypesActivity.from_dict(activity_item_data)

                activity.append(activity_item)

        _assignee_tasks = d.pop("assignee_tasks", UNSET)
        assignee_tasks: list[LegacytypesAssigneeTasks] | Unset = UNSET
        if _assignee_tasks is not UNSET:
            assignee_tasks = []
            for assignee_tasks_item_data in _assignee_tasks:
                assignee_tasks_item = LegacytypesAssigneeTasks.from_dict(assignee_tasks_item_data)

                assignee_tasks.append(assignee_tasks_item)

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

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

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

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

        _comments = d.pop("comments", UNSET)
        comments: list[LegacytypesComment] | Unset = UNSET
        if _comments is not UNSET:
            comments = []
            for comments_item_data in _comments:
                comments_item = LegacytypesComment.from_dict(comments_item_data)

                comments.append(comments_item)

        _compliance_status = d.pop("compliance_status", UNSET)
        compliance_status: LegacytypesRetirementPlanComplianceStatus | Unset
        if isinstance(_compliance_status, Unset):
            compliance_status = UNSET
        else:
            compliance_status = LegacytypesRetirementPlanComplianceStatus.from_dict(_compliance_status)

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

        _data = d.pop("data", UNSET)
        data: list[LegacytypesPlanYearData] | Unset = UNSET
        if _data is not UNSET:
            data = []
            for data_item_data in _data:
                data_item = LegacytypesPlanYearData.from_dict(data_item_data)

                data.append(data_item)

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

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

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

        _fields = d.pop("fields", UNSET)
        fields: list[LegacytypesField] | Unset = UNSET
        if _fields is not UNSET:
            fields = []
            for fields_item_data in _fields:
                fields_item = LegacytypesField.from_dict(fields_item_data)

                fields.append(fields_item)

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

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

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

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

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

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

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

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

        _plan_years = d.pop("plan_years", UNSET)
        plan_years: list[LegacytypesPlanYearProject] | Unset = UNSET
        if _plan_years is not UNSET:
            plan_years = []
            for plan_years_item_data in _plan_years:
                plan_years_item = LegacytypesPlanYearProject.from_dict(plan_years_item_data)

                plan_years.append(plan_years_item)

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

        _projects = d.pop("projects", UNSET)
        projects: list[LegacytypesProject] | Unset = UNSET
        if _projects is not UNSET:
            projects = []
            for projects_item_data in _projects:
                projects_item = LegacytypesProject.from_dict(projects_item_data)

                projects.append(projects_item)

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

                provisions.append(provisions_item)

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

        _rk = d.pop("rk", UNSET)
        rk: LegacytypesRetirementPlanRk | Unset
        if isinstance(_rk, Unset):
            rk = UNSET
        else:
            rk = LegacytypesRetirementPlanRk.from_dict(_rk)

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

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

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

        _tasks = d.pop("tasks", UNSET)
        tasks: list[LegacytypesTask] | Unset = UNSET
        if _tasks is not UNSET:
            tasks = []
            for tasks_item_data in _tasks:
                tasks_item = LegacytypesTask.from_dict(tasks_item_data)

                tasks.append(tasks_item)

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

        _totals = d.pop("totals", UNSET)
        totals: list[LegacytypesTransactionTotals] | Unset = UNSET
        if _totals is not UNSET:
            totals = []
            for totals_item_data in _totals:
                totals_item = LegacytypesTransactionTotals.from_dict(totals_item_data)

                totals.append(totals_item)

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

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

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

        legacytypes_retirement_plan = cls(
            field_id=field_id,
            accounts=accounts,
            activity=activity,
            assignee_tasks=assignee_tasks,
            bond=bond,
            carrier=carrier,
            client=client,
            code=code,
            comments=comments,
            compliance_status=compliance_status,
            created_at=created_at,
            data=data,
            deleted_at=deleted_at,
            effective_on=effective_on,
            employees=employees,
            fields=fields,
            ftw_census_grid=ftw_census_grid,
            name=name,
            notes=notes,
            owner_id=owner_id,
            owner_team=owner_team,
            parent_plan=parent_plan,
            participants=participants,
            plan_structure=plan_structure,
            plan_years=plan_years,
            primary_team_name=primary_team_name,
            projects=projects,
            provisions=provisions,
            pye=pye,
            rk=rk,
            sequence=sequence,
            status=status,
            tags=tags,
            tasks=tasks,
            team=team,
            totals=totals,
            tye=tye,
            type_=type_,
            view=view,
        )

        legacytypes_retirement_plan.additional_properties = d
        return legacytypes_retirement_plan

    @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
