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 ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.legacytypes_form_responder import LegacytypesFormResponder
    from ..models.legacytypes_response import LegacytypesResponse


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


@_attrs_define
class LegacytypesFormResponse:
    """
    Attributes:
        field_id (str | Unset):
        client (str | Unset): If filled out by client
        completed_at (int | Unset):
        contact (str | Unset): If filled out by contact
        deleted_at (int | Unset):
        device_agent (str | Unset):
        fields (str | Unset):
        form (str | Unset):
        ip (str | Unset):
        opened_at (int | Unset):
        pdf (str | Unset): Keep track of responses
        responder (LegacytypesFormResponder | Unset):
        responses (list[LegacytypesResponse] | Unset):
        sent_at (int | Unset):
        team (str | Unset):
        user (str | Unset):
    """

    field_id: str | Unset = UNSET
    client: str | Unset = UNSET
    completed_at: int | Unset = UNSET
    contact: str | Unset = UNSET
    deleted_at: int | Unset = UNSET
    device_agent: str | Unset = UNSET
    fields: str | Unset = UNSET
    form: str | Unset = UNSET
    ip: str | Unset = UNSET
    opened_at: int | Unset = UNSET
    pdf: str | Unset = UNSET
    responder: LegacytypesFormResponder | Unset = UNSET
    responses: list[LegacytypesResponse] | Unset = UNSET
    sent_at: int | Unset = UNSET
    team: str | Unset = UNSET
    user: 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

        client = self.client

        completed_at = self.completed_at

        contact = self.contact

        deleted_at = self.deleted_at

        device_agent = self.device_agent

        fields = self.fields

        form = self.form

        ip = self.ip

        opened_at = self.opened_at

        pdf = self.pdf

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

        responses: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.responses, Unset):
            responses = []
            for responses_item_data in self.responses:
                responses_item = responses_item_data.to_dict()
                responses.append(responses_item)

        sent_at = self.sent_at

        team = self.team

        user = self.user

        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 client is not UNSET:
            field_dict["client"] = client
        if completed_at is not UNSET:
            field_dict["completed_at"] = completed_at
        if contact is not UNSET:
            field_dict["contact"] = contact
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if device_agent is not UNSET:
            field_dict["device_agent"] = device_agent
        if fields is not UNSET:
            field_dict["fields"] = fields
        if form is not UNSET:
            field_dict["form"] = form
        if ip is not UNSET:
            field_dict["ip"] = ip
        if opened_at is not UNSET:
            field_dict["opened_at"] = opened_at
        if pdf is not UNSET:
            field_dict["pdf"] = pdf
        if responder is not UNSET:
            field_dict["responder"] = responder
        if responses is not UNSET:
            field_dict["responses"] = responses
        if sent_at is not UNSET:
            field_dict["sent_at"] = sent_at
        if team is not UNSET:
            field_dict["team"] = team
        if user is not UNSET:
            field_dict["user"] = user

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.legacytypes_form_responder import LegacytypesFormResponder
        from ..models.legacytypes_response import LegacytypesResponse

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

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

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

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

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

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

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

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

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

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

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

        _responder = d.pop("responder", UNSET)
        responder: LegacytypesFormResponder | Unset
        if isinstance(_responder, Unset):
            responder = UNSET
        else:
            responder = LegacytypesFormResponder.from_dict(_responder)

        _responses = d.pop("responses", UNSET)
        responses: list[LegacytypesResponse] | Unset = UNSET
        if _responses is not UNSET:
            responses = []
            for responses_item_data in _responses:
                responses_item = LegacytypesResponse.from_dict(responses_item_data)

                responses.append(responses_item)

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

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

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

        legacytypes_form_response = cls(
            field_id=field_id,
            client=client,
            completed_at=completed_at,
            contact=contact,
            deleted_at=deleted_at,
            device_agent=device_agent,
            fields=fields,
            form=form,
            ip=ip,
            opened_at=opened_at,
            pdf=pdf,
            responder=responder,
            responses=responses,
            sent_at=sent_at,
            team=team,
            user=user,
        )

        legacytypes_form_response.additional_properties = d
        return legacytypes_form_response

    @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
