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.types_client_role import TypesClientRole


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


@_attrs_define
class TypesSearchResultData:
    """
    Attributes:
        field_id (str | Unset):
        assignee (str | Unset): For projects
        clients (list[TypesClientRole] | Unset): For contacts
        date (str | Unset):
        detail (str | Unset): Email 1-line summary, task/project description/notes, file path
        due (str | Unset):
        email (str | Unset):
        flags (list[str] | Unset):
        incomplete_projects (int | Unset):
        incomplete_tasks (int | Unset):
        name (str | Unset):
        overdue_projects (int | Unset):
        overdue_tasks (int | Unset):
        parent (str | Unset): For files
        person (str | Unset): User/contact data if available
        pulse (int | Unset): For clients
        role (str | Unset):
        size (int | Unset):
        status (str | Unset):
        subject (str | Unset): For emails
        subtitle (str | Unset):
        tags (list[str] | Unset):
        total_tasks (int | Unset):
        type_ (str | Unset):
    """

    field_id: str | Unset = UNSET
    assignee: str | Unset = UNSET
    clients: list[TypesClientRole] | Unset = UNSET
    date: str | Unset = UNSET
    detail: str | Unset = UNSET
    due: str | Unset = UNSET
    email: str | Unset = UNSET
    flags: list[str] | Unset = UNSET
    incomplete_projects: int | Unset = UNSET
    incomplete_tasks: int | Unset = UNSET
    name: str | Unset = UNSET
    overdue_projects: int | Unset = UNSET
    overdue_tasks: int | Unset = UNSET
    parent: str | Unset = UNSET
    person: str | Unset = UNSET
    pulse: int | Unset = UNSET
    role: str | Unset = UNSET
    size: int | Unset = UNSET
    status: str | Unset = UNSET
    subject: str | Unset = UNSET
    subtitle: str | Unset = UNSET
    tags: list[str] | Unset = UNSET
    total_tasks: int | Unset = UNSET
    type_: 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

        assignee = self.assignee

        clients: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.clients, Unset):
            clients = []
            for clients_item_data in self.clients:
                clients_item = clients_item_data.to_dict()
                clients.append(clients_item)

        date = self.date

        detail = self.detail

        due = self.due

        email = self.email

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

        incomplete_projects = self.incomplete_projects

        incomplete_tasks = self.incomplete_tasks

        name = self.name

        overdue_projects = self.overdue_projects

        overdue_tasks = self.overdue_tasks

        parent = self.parent

        person = self.person

        pulse = self.pulse

        role = self.role

        size = self.size

        status = self.status

        subject = self.subject

        subtitle = self.subtitle

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

        total_tasks = self.total_tasks

        type_ = self.type_

        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 assignee is not UNSET:
            field_dict["assignee"] = assignee
        if clients is not UNSET:
            field_dict["clients"] = clients
        if date is not UNSET:
            field_dict["date"] = date
        if detail is not UNSET:
            field_dict["detail"] = detail
        if due is not UNSET:
            field_dict["due"] = due
        if email is not UNSET:
            field_dict["email"] = email
        if flags is not UNSET:
            field_dict["flags"] = flags
        if incomplete_projects is not UNSET:
            field_dict["incomplete_projects"] = incomplete_projects
        if incomplete_tasks is not UNSET:
            field_dict["incomplete_tasks"] = incomplete_tasks
        if name is not UNSET:
            field_dict["name"] = name
        if overdue_projects is not UNSET:
            field_dict["overdue_projects"] = overdue_projects
        if overdue_tasks is not UNSET:
            field_dict["overdue_tasks"] = overdue_tasks
        if parent is not UNSET:
            field_dict["parent"] = parent
        if person is not UNSET:
            field_dict["person"] = person
        if pulse is not UNSET:
            field_dict["pulse"] = pulse
        if role is not UNSET:
            field_dict["role"] = role
        if size is not UNSET:
            field_dict["size"] = size
        if status is not UNSET:
            field_dict["status"] = status
        if subject is not UNSET:
            field_dict["subject"] = subject
        if subtitle is not UNSET:
            field_dict["subtitle"] = subtitle
        if tags is not UNSET:
            field_dict["tags"] = tags
        if total_tasks is not UNSET:
            field_dict["total_tasks"] = total_tasks
        if type_ is not UNSET:
            field_dict["type"] = type_

        return field_dict

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

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

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

        _clients = d.pop("clients", UNSET)
        clients: list[TypesClientRole] | Unset = UNSET
        if _clients is not UNSET:
            clients = []
            for clients_item_data in _clients:
                clients_item = TypesClientRole.from_dict(clients_item_data)

                clients.append(clients_item)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        types_search_result_data = cls(
            field_id=field_id,
            assignee=assignee,
            clients=clients,
            date=date,
            detail=detail,
            due=due,
            email=email,
            flags=flags,
            incomplete_projects=incomplete_projects,
            incomplete_tasks=incomplete_tasks,
            name=name,
            overdue_projects=overdue_projects,
            overdue_tasks=overdue_tasks,
            parent=parent,
            person=person,
            pulse=pulse,
            role=role,
            size=size,
            status=status,
            subject=subject,
            subtitle=subtitle,
            tags=tags,
            total_tasks=total_tasks,
            type_=type_,
        )

        types_search_result_data.additional_properties = d
        return types_search_result_data

    @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
