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_integration_data import TypesIntegrationData


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


@_attrs_define
class TypesIntegration:
    """
    Attributes:
        field_id (str | Unset):
        api_key (str | Unset):
        created_by (str | Unset):
        created_on (str | Unset):
        data (TypesIntegrationData | Unset):
        deleted_at (str | Unset):
        enabled (bool | Unset):
        error (str | Unset):
        last_sync (str | Unset):
        password (str | Unset):
        team (str | Unset):
        template_id (str | Unset):
        type_ (str | Unset):
        user (str | Unset):
        username (str | Unset):
    """

    field_id: str | Unset = UNSET
    api_key: str | Unset = UNSET
    created_by: str | Unset = UNSET
    created_on: str | Unset = UNSET
    data: TypesIntegrationData | Unset = UNSET
    deleted_at: str | Unset = UNSET
    enabled: bool | Unset = UNSET
    error: str | Unset = UNSET
    last_sync: str | Unset = UNSET
    password: str | Unset = UNSET
    team: str | Unset = UNSET
    template_id: str | Unset = UNSET
    type_: str | Unset = UNSET
    user: str | Unset = UNSET
    username: 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

        api_key = self.api_key

        created_by = self.created_by

        created_on = self.created_on

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

        deleted_at = self.deleted_at

        enabled = self.enabled

        error = self.error

        last_sync = self.last_sync

        password = self.password

        team = self.team

        template_id = self.template_id

        type_ = self.type_

        user = self.user

        username = self.username

        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 api_key is not UNSET:
            field_dict["api_key"] = api_key
        if created_by is not UNSET:
            field_dict["created_by"] = created_by
        if created_on is not UNSET:
            field_dict["created_on"] = created_on
        if data is not UNSET:
            field_dict["data"] = data
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if enabled is not UNSET:
            field_dict["enabled"] = enabled
        if error is not UNSET:
            field_dict["error"] = error
        if last_sync is not UNSET:
            field_dict["last_sync"] = last_sync
        if password is not UNSET:
            field_dict["password"] = password
        if team is not UNSET:
            field_dict["team"] = team
        if template_id is not UNSET:
            field_dict["template_id"] = template_id
        if type_ is not UNSET:
            field_dict["type"] = type_
        if user is not UNSET:
            field_dict["user"] = user
        if username is not UNSET:
            field_dict["username"] = username

        return field_dict

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

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

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

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

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

        _data = d.pop("data", UNSET)
        data: TypesIntegrationData | Unset
        if isinstance(_data, Unset):
            data = UNSET
        else:
            data = TypesIntegrationData.from_dict(_data)

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

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

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

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

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

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

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

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

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

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

        types_integration = cls(
            field_id=field_id,
            api_key=api_key,
            created_by=created_by,
            created_on=created_on,
            data=data,
            deleted_at=deleted_at,
            enabled=enabled,
            error=error,
            last_sync=last_sync,
            password=password,
            team=team,
            template_id=template_id,
            type_=type_,
            user=user,
            username=username,
        )

        types_integration.additional_properties = d
        return types_integration

    @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
