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_automation_log import LegacytypesAutomationLog
    from ..models.legacytypes_client_task_data import LegacytypesClientTaskData
    from ..models.legacytypes_field import LegacytypesField
    from ..models.legacytypes_internal_task_data import LegacytypesInternalTaskData
    from ..models.legacytypes_meeting import LegacytypesMeeting
    from ..models.legacytypes_message import LegacytypesMessage
    from ..models.legacytypes_work_log import LegacytypesWorkLog


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


@_attrs_define
class LegacytypesTask:
    """
    Attributes:
        field_id (str | Unset):
        access (list[str] | Unset): Access control - this is essentially just a list of user IDs who have tasks the
            project this task belongs to that are assigned to them.
        activity (list[LegacytypesActivity] | Unset):
        assignee (str | Unset):
        automation (str | Unset): An automation may be used to complete the task
        automation_config (list[LegacytypesField] | Unset):
        automation_data (Any | Unset):
        automation_logs (list[LegacytypesAutomationLog] | Unset):
        client (str | Unset):
        client_task_data (LegacytypesClientTaskData | Unset):
        client_task_type (str | Unset): If this is a task for the client to do, a client task type should be set - eg.
            "Census Data Collection", "Census Data Review", "Participant Notices", "Fill Web or Document Form", "Testing
            Corrections", "Other"
        completed_at (str | Unset):
        created_at (str | Unset): Time tracking
        deleted_at (str | Unset):
        description (str | Unset):
        due (str | Unset):
        fields_to_complete (list[str] | Unset): If the task belongs to a project, it can require collecting specified
            fields for the project
        flagged_at (str | Unset): By automation
        internal_task_data (LegacytypesInternalTaskData | Unset):
        internal_task_type (str | Unset): If this is a special type (eg. payroll mapping, form selection, etc.), an
            internal task type should be set.
        last_follow_up (str | Unset):
        log_completion_to (str | Unset):
        log_completion_type (str | Unset): Log completion time to project variable?
        meeting (LegacytypesMeeting | Unset):
        message (LegacytypesMessage | Unset):
        next_at (str | Unset):
        notes (str | Unset):
        order (int | Unset): If the task is part of a project, the order should be tracked
        plan (str | Unset):
        priority (int | Unset):
        project (str | Unset):
        started_at (str | Unset):
        suggestion (int | Unset):
        team (str | Unset):
        team_wide_access (bool | Unset): Team-wide access - if true, all team members have access to this project
        template (str | Unset):
        work_logs (list[LegacytypesWorkLog] | Unset): Work logs
    """

    field_id: str | Unset = UNSET
    access: list[str] | Unset = UNSET
    activity: list[LegacytypesActivity] | Unset = UNSET
    assignee: str | Unset = UNSET
    automation: str | Unset = UNSET
    automation_config: list[LegacytypesField] | Unset = UNSET
    automation_data: Any | Unset = UNSET
    automation_logs: list[LegacytypesAutomationLog] | Unset = UNSET
    client: str | Unset = UNSET
    client_task_data: LegacytypesClientTaskData | Unset = UNSET
    client_task_type: str | Unset = UNSET
    completed_at: str | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    description: str | Unset = UNSET
    due: str | Unset = UNSET
    fields_to_complete: list[str] | Unset = UNSET
    flagged_at: str | Unset = UNSET
    internal_task_data: LegacytypesInternalTaskData | Unset = UNSET
    internal_task_type: str | Unset = UNSET
    last_follow_up: str | Unset = UNSET
    log_completion_to: str | Unset = UNSET
    log_completion_type: str | Unset = UNSET
    meeting: LegacytypesMeeting | Unset = UNSET
    message: LegacytypesMessage | Unset = UNSET
    next_at: str | Unset = UNSET
    notes: str | Unset = UNSET
    order: int | Unset = UNSET
    plan: str | Unset = UNSET
    priority: int | Unset = UNSET
    project: str | Unset = UNSET
    started_at: str | Unset = UNSET
    suggestion: int | Unset = UNSET
    team: str | Unset = UNSET
    team_wide_access: bool | Unset = UNSET
    template: str | Unset = UNSET
    work_logs: list[LegacytypesWorkLog] | 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

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

        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 = self.assignee

        automation = self.automation

        automation_config: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.automation_config, Unset):
            automation_config = []
            for automation_config_item_data in self.automation_config:
                automation_config_item = automation_config_item_data.to_dict()
                automation_config.append(automation_config_item)

        automation_data = self.automation_data

        automation_logs: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.automation_logs, Unset):
            automation_logs = []
            for automation_logs_item_data in self.automation_logs:
                automation_logs_item = automation_logs_item_data.to_dict()
                automation_logs.append(automation_logs_item)

        client = self.client

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

        client_task_type = self.client_task_type

        completed_at = self.completed_at

        created_at = self.created_at

        deleted_at = self.deleted_at

        description = self.description

        due = self.due

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

        flagged_at = self.flagged_at

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

        internal_task_type = self.internal_task_type

        last_follow_up = self.last_follow_up

        log_completion_to = self.log_completion_to

        log_completion_type = self.log_completion_type

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

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

        next_at = self.next_at

        notes = self.notes

        order = self.order

        plan = self.plan

        priority = self.priority

        project = self.project

        started_at = self.started_at

        suggestion = self.suggestion

        team = self.team

        team_wide_access = self.team_wide_access

        template = self.template

        work_logs: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.work_logs, Unset):
            work_logs = []
            for work_logs_item_data in self.work_logs:
                work_logs_item = work_logs_item_data.to_dict()
                work_logs.append(work_logs_item)

        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 access is not UNSET:
            field_dict["access"] = access
        if activity is not UNSET:
            field_dict["activity"] = activity
        if assignee is not UNSET:
            field_dict["assignee"] = assignee
        if automation is not UNSET:
            field_dict["automation"] = automation
        if automation_config is not UNSET:
            field_dict["automation_config"] = automation_config
        if automation_data is not UNSET:
            field_dict["automation_data"] = automation_data
        if automation_logs is not UNSET:
            field_dict["automation_logs"] = automation_logs
        if client is not UNSET:
            field_dict["client"] = client
        if client_task_data is not UNSET:
            field_dict["client_task_data"] = client_task_data
        if client_task_type is not UNSET:
            field_dict["client_task_type"] = client_task_type
        if completed_at is not UNSET:
            field_dict["completed_at"] = completed_at
        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 due is not UNSET:
            field_dict["due"] = due
        if fields_to_complete is not UNSET:
            field_dict["fields_to_complete"] = fields_to_complete
        if flagged_at is not UNSET:
            field_dict["flagged_at"] = flagged_at
        if internal_task_data is not UNSET:
            field_dict["internal_task_data"] = internal_task_data
        if internal_task_type is not UNSET:
            field_dict["internal_task_type"] = internal_task_type
        if last_follow_up is not UNSET:
            field_dict["last_follow_up"] = last_follow_up
        if log_completion_to is not UNSET:
            field_dict["log_completion_to"] = log_completion_to
        if log_completion_type is not UNSET:
            field_dict["log_completion_type"] = log_completion_type
        if meeting is not UNSET:
            field_dict["meeting"] = meeting
        if message is not UNSET:
            field_dict["message"] = message
        if next_at is not UNSET:
            field_dict["next_at"] = next_at
        if notes is not UNSET:
            field_dict["notes"] = notes
        if order is not UNSET:
            field_dict["order"] = order
        if plan is not UNSET:
            field_dict["plan"] = plan
        if priority is not UNSET:
            field_dict["priority"] = priority
        if project is not UNSET:
            field_dict["project"] = project
        if started_at is not UNSET:
            field_dict["started_at"] = started_at
        if suggestion is not UNSET:
            field_dict["suggestion"] = suggestion
        if team is not UNSET:
            field_dict["team"] = team
        if team_wide_access is not UNSET:
            field_dict["team_wide_access"] = team_wide_access
        if template is not UNSET:
            field_dict["template"] = template
        if work_logs is not UNSET:
            field_dict["work_logs"] = work_logs

        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_automation_log import LegacytypesAutomationLog
        from ..models.legacytypes_client_task_data import LegacytypesClientTaskData
        from ..models.legacytypes_field import LegacytypesField
        from ..models.legacytypes_internal_task_data import LegacytypesInternalTaskData
        from ..models.legacytypes_meeting import LegacytypesMeeting
        from ..models.legacytypes_message import LegacytypesMessage
        from ..models.legacytypes_work_log import LegacytypesWorkLog

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

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

        _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 = d.pop("assignee", UNSET)

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

        _automation_config = d.pop("automation_config", UNSET)
        automation_config: list[LegacytypesField] | Unset = UNSET
        if _automation_config is not UNSET:
            automation_config = []
            for automation_config_item_data in _automation_config:
                automation_config_item = LegacytypesField.from_dict(automation_config_item_data)

                automation_config.append(automation_config_item)

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

        _automation_logs = d.pop("automation_logs", UNSET)
        automation_logs: list[LegacytypesAutomationLog] | Unset = UNSET
        if _automation_logs is not UNSET:
            automation_logs = []
            for automation_logs_item_data in _automation_logs:
                automation_logs_item = LegacytypesAutomationLog.from_dict(automation_logs_item_data)

                automation_logs.append(automation_logs_item)

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

        _client_task_data = d.pop("client_task_data", UNSET)
        client_task_data: LegacytypesClientTaskData | Unset
        if isinstance(_client_task_data, Unset):
            client_task_data = UNSET
        else:
            client_task_data = LegacytypesClientTaskData.from_dict(_client_task_data)

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

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

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

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

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

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

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

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

        _internal_task_data = d.pop("internal_task_data", UNSET)
        internal_task_data: LegacytypesInternalTaskData | Unset
        if isinstance(_internal_task_data, Unset):
            internal_task_data = UNSET
        else:
            internal_task_data = LegacytypesInternalTaskData.from_dict(_internal_task_data)

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

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

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

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

        _meeting = d.pop("meeting", UNSET)
        meeting: LegacytypesMeeting | Unset
        if isinstance(_meeting, Unset):
            meeting = UNSET
        else:
            meeting = LegacytypesMeeting.from_dict(_meeting)

        _message = d.pop("message", UNSET)
        message: LegacytypesMessage | Unset
        if isinstance(_message, Unset):
            message = UNSET
        else:
            message = LegacytypesMessage.from_dict(_message)

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

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

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

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

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

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

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

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

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

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

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

        _work_logs = d.pop("work_logs", UNSET)
        work_logs: list[LegacytypesWorkLog] | Unset = UNSET
        if _work_logs is not UNSET:
            work_logs = []
            for work_logs_item_data in _work_logs:
                work_logs_item = LegacytypesWorkLog.from_dict(work_logs_item_data)

                work_logs.append(work_logs_item)

        legacytypes_task = cls(
            field_id=field_id,
            access=access,
            activity=activity,
            assignee=assignee,
            automation=automation,
            automation_config=automation_config,
            automation_data=automation_data,
            automation_logs=automation_logs,
            client=client,
            client_task_data=client_task_data,
            client_task_type=client_task_type,
            completed_at=completed_at,
            created_at=created_at,
            deleted_at=deleted_at,
            description=description,
            due=due,
            fields_to_complete=fields_to_complete,
            flagged_at=flagged_at,
            internal_task_data=internal_task_data,
            internal_task_type=internal_task_type,
            last_follow_up=last_follow_up,
            log_completion_to=log_completion_to,
            log_completion_type=log_completion_type,
            meeting=meeting,
            message=message,
            next_at=next_at,
            notes=notes,
            order=order,
            plan=plan,
            priority=priority,
            project=project,
            started_at=started_at,
            suggestion=suggestion,
            team=team,
            team_wide_access=team_wide_access,
            template=template,
            work_logs=work_logs,
        )

        legacytypes_task.additional_properties = d
        return legacytypes_task

    @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
