from __future__ import annotations

import datetime
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 dateutil.parser import isoparse

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.billing import Billing
    from ..models.email_config import EmailConfig
    from ..models.fax_config import FaxConfig
    from ..models.integrations import Integrations
    from ..models.quick_access import QuickAccess
    from ..models.savings import Savings
    from ..models.security import Security
    from ..models.sync_config import SyncConfig
    from ..models.trust_accounting import TrustAccounting


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


@_attrs_define
class Team:
    """
    Attributes:
        field_id (str | Unset): MongoDB ObjectId
        subdomain (str | Unset):
        name (str | Unset):
        owner (str | Unset): MongoDB ObjectId
        creation_date (datetime.datetime | Unset):
        billing (Billing | Unset):
        email (EmailConfig | Unset):
        fax (FaxConfig | Unset):
        sync (SyncConfig | Unset): Synchronization configuration for various cloud storage providers
        ta (TrustAccounting | Unset):
        num_pages_stored (float | Unset):
        num_pages_archived (float | Unset):
        num_stacks (float | Unset):
        savings (list[Savings] | Unset):
        total_pages_processed (float | Unset):
        total_seconds_saved (float | Unset):
        auto_archive (float | Unset):
        auto_review (bool | Unset):
        quick_access (QuickAccess | Unset):
        document_retention (float | Unset):
        security (Security | Unset):
        developer (bool | Unset):
        integrations (Integrations | Unset):
        scopes (list[str] | Unset):
        source (str | Unset):
        deal (float | Unset):
        remote (bool | Unset):
    """

    field_id: str | Unset = UNSET
    subdomain: str | Unset = UNSET
    name: str | Unset = UNSET
    owner: str | Unset = UNSET
    creation_date: datetime.datetime | Unset = UNSET
    billing: Billing | Unset = UNSET
    email: EmailConfig | Unset = UNSET
    fax: FaxConfig | Unset = UNSET
    sync: SyncConfig | Unset = UNSET
    ta: TrustAccounting | Unset = UNSET
    num_pages_stored: float | Unset = UNSET
    num_pages_archived: float | Unset = UNSET
    num_stacks: float | Unset = UNSET
    savings: list[Savings] | Unset = UNSET
    total_pages_processed: float | Unset = UNSET
    total_seconds_saved: float | Unset = UNSET
    auto_archive: float | Unset = UNSET
    auto_review: bool | Unset = UNSET
    quick_access: QuickAccess | Unset = UNSET
    document_retention: float | Unset = UNSET
    security: Security | Unset = UNSET
    developer: bool | Unset = UNSET
    integrations: Integrations | Unset = UNSET
    scopes: list[str] | Unset = UNSET
    source: str | Unset = UNSET
    deal: float | Unset = UNSET
    remote: 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

        subdomain = self.subdomain

        name = self.name

        owner = self.owner

        creation_date: str | Unset = UNSET
        if not isinstance(self.creation_date, Unset):
            creation_date = self.creation_date.isoformat()

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

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

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

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

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

        num_pages_stored = self.num_pages_stored

        num_pages_archived = self.num_pages_archived

        num_stacks = self.num_stacks

        savings: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.savings, Unset):
            savings = []
            for savings_item_data in self.savings:
                savings_item = savings_item_data.to_dict()
                savings.append(savings_item)

        total_pages_processed = self.total_pages_processed

        total_seconds_saved = self.total_seconds_saved

        auto_archive = self.auto_archive

        auto_review = self.auto_review

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

        document_retention = self.document_retention

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

        developer = self.developer

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

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

        source = self.source

        deal = self.deal

        remote = self.remote

        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 subdomain is not UNSET:
            field_dict["subdomain"] = subdomain
        if name is not UNSET:
            field_dict["name"] = name
        if owner is not UNSET:
            field_dict["owner"] = owner
        if creation_date is not UNSET:
            field_dict["creationDate"] = creation_date
        if billing is not UNSET:
            field_dict["billing"] = billing
        if email is not UNSET:
            field_dict["email"] = email
        if fax is not UNSET:
            field_dict["fax"] = fax
        if sync is not UNSET:
            field_dict["sync"] = sync
        if ta is not UNSET:
            field_dict["ta"] = ta
        if num_pages_stored is not UNSET:
            field_dict["numPagesStored"] = num_pages_stored
        if num_pages_archived is not UNSET:
            field_dict["numPagesArchived"] = num_pages_archived
        if num_stacks is not UNSET:
            field_dict["numStacks"] = num_stacks
        if savings is not UNSET:
            field_dict["savings"] = savings
        if total_pages_processed is not UNSET:
            field_dict["totalPagesProcessed"] = total_pages_processed
        if total_seconds_saved is not UNSET:
            field_dict["totalSecondsSaved"] = total_seconds_saved
        if auto_archive is not UNSET:
            field_dict["autoArchive"] = auto_archive
        if auto_review is not UNSET:
            field_dict["autoReview"] = auto_review
        if quick_access is not UNSET:
            field_dict["quickAccess"] = quick_access
        if document_retention is not UNSET:
            field_dict["documentRetention"] = document_retention
        if security is not UNSET:
            field_dict["security"] = security
        if developer is not UNSET:
            field_dict["developer"] = developer
        if integrations is not UNSET:
            field_dict["integrations"] = integrations
        if scopes is not UNSET:
            field_dict["scopes"] = scopes
        if source is not UNSET:
            field_dict["source"] = source
        if deal is not UNSET:
            field_dict["deal"] = deal
        if remote is not UNSET:
            field_dict["remote"] = remote

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.billing import Billing
        from ..models.email_config import EmailConfig
        from ..models.fax_config import FaxConfig
        from ..models.integrations import Integrations
        from ..models.quick_access import QuickAccess
        from ..models.savings import Savings
        from ..models.security import Security
        from ..models.sync_config import SyncConfig
        from ..models.trust_accounting import TrustAccounting

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

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

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

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

        _creation_date = d.pop("creationDate", UNSET)
        creation_date: datetime.datetime | Unset
        if isinstance(_creation_date, Unset):
            creation_date = UNSET
        else:
            creation_date = isoparse(_creation_date)

        _billing = d.pop("billing", UNSET)
        billing: Billing | Unset
        if isinstance(_billing, Unset):
            billing = UNSET
        else:
            billing = Billing.from_dict(_billing)

        _email = d.pop("email", UNSET)
        email: EmailConfig | Unset
        if isinstance(_email, Unset):
            email = UNSET
        else:
            email = EmailConfig.from_dict(_email)

        _fax = d.pop("fax", UNSET)
        fax: FaxConfig | Unset
        if isinstance(_fax, Unset):
            fax = UNSET
        else:
            fax = FaxConfig.from_dict(_fax)

        _sync = d.pop("sync", UNSET)
        sync: SyncConfig | Unset
        if isinstance(_sync, Unset):
            sync = UNSET
        else:
            sync = SyncConfig.from_dict(_sync)

        _ta = d.pop("ta", UNSET)
        ta: TrustAccounting | Unset
        if isinstance(_ta, Unset):
            ta = UNSET
        else:
            ta = TrustAccounting.from_dict(_ta)

        num_pages_stored = d.pop("numPagesStored", UNSET)

        num_pages_archived = d.pop("numPagesArchived", UNSET)

        num_stacks = d.pop("numStacks", UNSET)

        _savings = d.pop("savings", UNSET)
        savings: list[Savings] | Unset = UNSET
        if _savings is not UNSET:
            savings = []
            for savings_item_data in _savings:
                savings_item = Savings.from_dict(savings_item_data)

                savings.append(savings_item)

        total_pages_processed = d.pop("totalPagesProcessed", UNSET)

        total_seconds_saved = d.pop("totalSecondsSaved", UNSET)

        auto_archive = d.pop("autoArchive", UNSET)

        auto_review = d.pop("autoReview", UNSET)

        _quick_access = d.pop("quickAccess", UNSET)
        quick_access: QuickAccess | Unset
        if isinstance(_quick_access, Unset):
            quick_access = UNSET
        else:
            quick_access = QuickAccess.from_dict(_quick_access)

        document_retention = d.pop("documentRetention", UNSET)

        _security = d.pop("security", UNSET)
        security: Security | Unset
        if isinstance(_security, Unset):
            security = UNSET
        else:
            security = Security.from_dict(_security)

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

        _integrations = d.pop("integrations", UNSET)
        integrations: Integrations | Unset
        if isinstance(_integrations, Unset):
            integrations = UNSET
        else:
            integrations = Integrations.from_dict(_integrations)

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

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

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

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

        team = cls(
            field_id=field_id,
            subdomain=subdomain,
            name=name,
            owner=owner,
            creation_date=creation_date,
            billing=billing,
            email=email,
            fax=fax,
            sync=sync,
            ta=ta,
            num_pages_stored=num_pages_stored,
            num_pages_archived=num_pages_archived,
            num_stacks=num_stacks,
            savings=savings,
            total_pages_processed=total_pages_processed,
            total_seconds_saved=total_seconds_saved,
            auto_archive=auto_archive,
            auto_review=auto_review,
            quick_access=quick_access,
            document_retention=document_retention,
            security=security,
            developer=developer,
            integrations=integrations,
            scopes=scopes,
            source=source,
            deal=deal,
            remote=remote,
        )

        team.additional_properties = d
        return team

    @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
