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.types_activity import TypesActivity
    from ..models.types_client import TypesClient
    from ..models.types_collaborator_access import TypesCollaboratorAccess
    from ..models.types_comment import TypesComment
    from ..models.types_external_upload import TypesExternalUpload
    from ..models.types_field import TypesField
    from ..models.types_file_access import TypesFileAccess
    from ..models.types_file_lock import TypesFileLock
    from ..models.types_form_response import TypesFormResponse
    from ..models.types_form_template import TypesFormTemplate
    from ..models.types_parent import TypesParent
    from ..models.types_upload_key import TypesUploadKey


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


@_attrs_define
class TypesFile:
    """
    Attributes:
        field_id (str | Unset):
        absolute_path (str | Unset):
        access (list[TypesFileAccess] | Unset):
        activity (list[TypesActivity] | Unset):
        client (TypesClient | Unset):
        collaborators (list[TypesCollaboratorAccess] | Unset):
        comments (list[TypesComment] | Unset):
        context (str | Unset): Context is used to process the file
        cp_upload (TypesExternalUpload | Unset):
        created_at (str | Unset):
        created_by (str | Unset):
        created_by_type (str | Unset):
        deleted_at (str | Unset):
        favorite (bool | Unset):
        fields (list[TypesField] | Unset):
        form (TypesFormTemplate | Unset):
        hidden (bool | Unset):
        lock (TypesFileLock | Unset):
        locked (bool | Unset):
        mime_type (str | Unset):
        modified_at (str | Unset):
        name (str | Unset):
        parent (str | Unset):
        path (list[TypesParent] | Unset): For returning
        responses (list[TypesFormResponse] | Unset):
        share_root (str | Unset):
        share_token (str | Unset):
        size (int | Unset):
        team (str | Unset):
        type_ (str | Unset): File mimetype or "folder"
        upload_keys (list[TypesUploadKey] | Unset): If this is a folder and this is set, then users can anonymously
            upload to this folder if they have the link
        url (str | Unset): Presigned URL to download the file
        writeable (bool | Unset): True if this user is able to write to the file
    """

    field_id: str | Unset = UNSET
    absolute_path: str | Unset = UNSET
    access: list[TypesFileAccess] | Unset = UNSET
    activity: list[TypesActivity] | Unset = UNSET
    client: TypesClient | Unset = UNSET
    collaborators: list[TypesCollaboratorAccess] | Unset = UNSET
    comments: list[TypesComment] | Unset = UNSET
    context: str | Unset = UNSET
    cp_upload: TypesExternalUpload | Unset = UNSET
    created_at: str | Unset = UNSET
    created_by: str | Unset = UNSET
    created_by_type: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    favorite: bool | Unset = UNSET
    fields: list[TypesField] | Unset = UNSET
    form: TypesFormTemplate | Unset = UNSET
    hidden: bool | Unset = UNSET
    lock: TypesFileLock | Unset = UNSET
    locked: bool | Unset = UNSET
    mime_type: str | Unset = UNSET
    modified_at: str | Unset = UNSET
    name: str | Unset = UNSET
    parent: str | Unset = UNSET
    path: list[TypesParent] | Unset = UNSET
    responses: list[TypesFormResponse] | Unset = UNSET
    share_root: str | Unset = UNSET
    share_token: str | Unset = UNSET
    size: int | Unset = UNSET
    team: str | Unset = UNSET
    type_: str | Unset = UNSET
    upload_keys: list[TypesUploadKey] | Unset = UNSET
    url: str | Unset = UNSET
    writeable: bool | 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

        absolute_path = self.absolute_path

        access: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.access, Unset):
            access = []
            for access_item_data in self.access:
                access_item = access_item_data.to_dict()
                access.append(access_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)

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

        collaborators: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.collaborators, Unset):
            collaborators = []
            for collaborators_item_data in self.collaborators:
                collaborators_item = collaborators_item_data.to_dict()
                collaborators.append(collaborators_item)

        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)

        context = self.context

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

        created_at = self.created_at

        created_by = self.created_by

        created_by_type = self.created_by_type

        deleted_at = self.deleted_at

        favorite = self.favorite

        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)

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

        hidden = self.hidden

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

        locked = self.locked

        mime_type = self.mime_type

        modified_at = self.modified_at

        name = self.name

        parent = self.parent

        path: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.path, Unset):
            path = []
            for path_item_data in self.path:
                path_item = path_item_data.to_dict()
                path.append(path_item)

        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)

        share_root = self.share_root

        share_token = self.share_token

        size = self.size

        team = self.team

        type_ = self.type_

        upload_keys: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.upload_keys, Unset):
            upload_keys = []
            for upload_keys_item_data in self.upload_keys:
                upload_keys_item = upload_keys_item_data.to_dict()
                upload_keys.append(upload_keys_item)

        url = self.url

        writeable = self.writeable

        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 absolute_path is not UNSET:
            field_dict["absolute_path"] = absolute_path
        if access is not UNSET:
            field_dict["access"] = access
        if activity is not UNSET:
            field_dict["activity"] = activity
        if client is not UNSET:
            field_dict["client"] = client
        if collaborators is not UNSET:
            field_dict["collaborators"] = collaborators
        if comments is not UNSET:
            field_dict["comments"] = comments
        if context is not UNSET:
            field_dict["context"] = context
        if cp_upload is not UNSET:
            field_dict["cp_upload"] = cp_upload
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if created_by is not UNSET:
            field_dict["created_by"] = created_by
        if created_by_type is not UNSET:
            field_dict["created_by_type"] = created_by_type
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if favorite is not UNSET:
            field_dict["favorite"] = favorite
        if fields is not UNSET:
            field_dict["fields"] = fields
        if form is not UNSET:
            field_dict["form"] = form
        if hidden is not UNSET:
            field_dict["hidden"] = hidden
        if lock is not UNSET:
            field_dict["lock"] = lock
        if locked is not UNSET:
            field_dict["locked"] = locked
        if mime_type is not UNSET:
            field_dict["mime_type"] = mime_type
        if modified_at is not UNSET:
            field_dict["modified_at"] = modified_at
        if name is not UNSET:
            field_dict["name"] = name
        if parent is not UNSET:
            field_dict["parent"] = parent
        if path is not UNSET:
            field_dict["path"] = path
        if responses is not UNSET:
            field_dict["responses"] = responses
        if share_root is not UNSET:
            field_dict["share_root"] = share_root
        if share_token is not UNSET:
            field_dict["share_token"] = share_token
        if size is not UNSET:
            field_dict["size"] = size
        if team is not UNSET:
            field_dict["team"] = team
        if type_ is not UNSET:
            field_dict["type"] = type_
        if upload_keys is not UNSET:
            field_dict["upload_keys"] = upload_keys
        if url is not UNSET:
            field_dict["url"] = url
        if writeable is not UNSET:
            field_dict["writeable"] = writeable

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_activity import TypesActivity
        from ..models.types_client import TypesClient
        from ..models.types_collaborator_access import TypesCollaboratorAccess
        from ..models.types_comment import TypesComment
        from ..models.types_external_upload import TypesExternalUpload
        from ..models.types_field import TypesField
        from ..models.types_file_access import TypesFileAccess
        from ..models.types_file_lock import TypesFileLock
        from ..models.types_form_response import TypesFormResponse
        from ..models.types_form_template import TypesFormTemplate
        from ..models.types_parent import TypesParent
        from ..models.types_upload_key import TypesUploadKey

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

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

        _access = d.pop("access", UNSET)
        access: list[TypesFileAccess] | Unset = UNSET
        if _access is not UNSET:
            access = []
            for access_item_data in _access:
                access_item = TypesFileAccess.from_dict(access_item_data)

                access.append(access_item)

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

                activity.append(activity_item)

        _client = d.pop("client", UNSET)
        client: TypesClient | Unset
        if isinstance(_client, Unset):
            client = UNSET
        else:
            client = TypesClient.from_dict(_client)

        _collaborators = d.pop("collaborators", UNSET)
        collaborators: list[TypesCollaboratorAccess] | Unset = UNSET
        if _collaborators is not UNSET:
            collaborators = []
            for collaborators_item_data in _collaborators:
                collaborators_item = TypesCollaboratorAccess.from_dict(collaborators_item_data)

                collaborators.append(collaborators_item)

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

                comments.append(comments_item)

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

        _cp_upload = d.pop("cp_upload", UNSET)
        cp_upload: TypesExternalUpload | Unset
        if isinstance(_cp_upload, Unset):
            cp_upload = UNSET
        else:
            cp_upload = TypesExternalUpload.from_dict(_cp_upload)

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

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

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

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

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

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

                fields.append(fields_item)

        _form = d.pop("form", UNSET)
        form: TypesFormTemplate | Unset
        if isinstance(_form, Unset):
            form = UNSET
        else:
            form = TypesFormTemplate.from_dict(_form)

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

        _lock = d.pop("lock", UNSET)
        lock: TypesFileLock | Unset
        if isinstance(_lock, Unset):
            lock = UNSET
        else:
            lock = TypesFileLock.from_dict(_lock)

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

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

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

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

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

        _path = d.pop("path", UNSET)
        path: list[TypesParent] | Unset = UNSET
        if _path is not UNSET:
            path = []
            for path_item_data in _path:
                path_item = TypesParent.from_dict(path_item_data)

                path.append(path_item)

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

                responses.append(responses_item)

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

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

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

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

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

        _upload_keys = d.pop("upload_keys", UNSET)
        upload_keys: list[TypesUploadKey] | Unset = UNSET
        if _upload_keys is not UNSET:
            upload_keys = []
            for upload_keys_item_data in _upload_keys:
                upload_keys_item = TypesUploadKey.from_dict(upload_keys_item_data)

                upload_keys.append(upload_keys_item)

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

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

        types_file = cls(
            field_id=field_id,
            absolute_path=absolute_path,
            access=access,
            activity=activity,
            client=client,
            collaborators=collaborators,
            comments=comments,
            context=context,
            cp_upload=cp_upload,
            created_at=created_at,
            created_by=created_by,
            created_by_type=created_by_type,
            deleted_at=deleted_at,
            favorite=favorite,
            fields=fields,
            form=form,
            hidden=hidden,
            lock=lock,
            locked=locked,
            mime_type=mime_type,
            modified_at=modified_at,
            name=name,
            parent=parent,
            path=path,
            responses=responses,
            share_root=share_root,
            share_token=share_token,
            size=size,
            team=team,
            type_=type_,
            upload_keys=upload_keys,
            url=url,
            writeable=writeable,
        )

        types_file.additional_properties = d
        return types_file

    @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
