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_file_link_use import LegacytypesFileLinkUse


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


@_attrs_define
class LegacytypesFileLink:
    """
    Attributes:
        field_id (str | Unset):
        created_at (str | Unset):
        created_by (str | Unset):
        created_by_type (str | Unset):
        deleted_at (str | Unset):
        expires_at (str | Unset):
        file (str | Unset):
        name (str | Unset):
        number_of_uses (int | Unset):
        team (str | Unset):
        token (str | Unset):
        used_at (str | Unset):
        uses (list[LegacytypesFileLinkUse] | Unset):
    """

    field_id: str | Unset = UNSET
    created_at: str | Unset = UNSET
    created_by: str | Unset = UNSET
    created_by_type: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    expires_at: str | Unset = UNSET
    file: str | Unset = UNSET
    name: str | Unset = UNSET
    number_of_uses: int | Unset = UNSET
    team: str | Unset = UNSET
    token: str | Unset = UNSET
    used_at: str | Unset = UNSET
    uses: list[LegacytypesFileLinkUse] | 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

        created_at = self.created_at

        created_by = self.created_by

        created_by_type = self.created_by_type

        deleted_at = self.deleted_at

        expires_at = self.expires_at

        file = self.file

        name = self.name

        number_of_uses = self.number_of_uses

        team = self.team

        token = self.token

        used_at = self.used_at

        uses: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.uses, Unset):
            uses = []
            for uses_item_data in self.uses:
                uses_item = uses_item_data.to_dict()
                uses.append(uses_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 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 expires_at is not UNSET:
            field_dict["expires_at"] = expires_at
        if file is not UNSET:
            field_dict["file"] = file
        if name is not UNSET:
            field_dict["name"] = name
        if number_of_uses is not UNSET:
            field_dict["number_of_uses"] = number_of_uses
        if team is not UNSET:
            field_dict["team"] = team
        if token is not UNSET:
            field_dict["token"] = token
        if used_at is not UNSET:
            field_dict["used_at"] = used_at
        if uses is not UNSET:
            field_dict["uses"] = uses

        return field_dict

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

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

        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)

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

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

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

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

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

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

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

        _uses = d.pop("uses", UNSET)
        uses: list[LegacytypesFileLinkUse] | Unset = UNSET
        if _uses is not UNSET:
            uses = []
            for uses_item_data in _uses:
                uses_item = LegacytypesFileLinkUse.from_dict(uses_item_data)

                uses.append(uses_item)

        legacytypes_file_link = cls(
            field_id=field_id,
            created_at=created_at,
            created_by=created_by,
            created_by_type=created_by_type,
            deleted_at=deleted_at,
            expires_at=expires_at,
            file=file,
            name=name,
            number_of_uses=number_of_uses,
            team=team,
            token=token,
            used_at=used_at,
            uses=uses,
        )

        legacytypes_file_link.additional_properties = d
        return legacytypes_file_link

    @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
