# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any, Literal, cast

from workos._types import _raise_deserialize_error
from workos.common.models.data_integrations_list_response_data_auth_methods import (
    DataIntegrationsListResponseDataAuthMethods,
)
from workos.common.models.data_integrations_list_response_data_ownership import (
    DataIntegrationsListResponseDataOwnership,
)

from .data_integrations_list_response_data_connected_account import (
    DataIntegrationsListResponseDataConnectedAccount,
)


@dataclass(slots=True)
class DataIntegrationsListResponseData:
    """Data Integrations List Response Data model."""

    object: Literal["data_provider"]
    """Distinguishes the data provider object."""
    id: str
    """The unique identifier of the provider."""
    name: str
    """The display name of the provider (e.g., "GitHub", "Slack")."""
    description: str | None
    """A description of the provider explaining how it will be used, if configured."""
    slug: str
    """The slug identifier used in API calls (e.g., `github`, `slack`, `notion`)."""
    integration_type: str
    """The type of integration (e.g., `github`, `slack`)."""
    credentials_type: str
    """The type of credentials used by the provider (e.g., `oauth2`)."""
    scopes: list[str] | None
    """The OAuth scopes configured for this provider, or `null` if none are configured."""
    ownership: DataIntegrationsListResponseDataOwnership
    """Whether the provider is owned by a user or organization."""
    created_at: str
    """The timestamp when the provider was created."""
    updated_at: str
    """The timestamp when the provider was last updated."""
    connected_account: DataIntegrationsListResponseDataConnectedAccount | None
    """The user's [connected account](https://workos.com/docs/reference/pipes/connected-account) for this provider, or `null` if the user has not connected."""
    auth_methods: list[DataIntegrationsListResponseDataAuthMethods] | None = None
    """The authentication methods supported by this provider (`oauth`, `api_key`, `client_credentials`, or a combination). Defaults to `["oauth"]` if absent."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationsListResponseData:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "data_provider"),
                id=data["id"],
                name=data["name"],
                description=data["description"],
                slug=data["slug"],
                integration_type=data["integration_type"],
                credentials_type=data["credentials_type"],
                scopes=data["scopes"],
                ownership=DataIntegrationsListResponseDataOwnership(data["ownership"]),
                created_at=data["created_at"],
                updated_at=data["updated_at"],
                connected_account=DataIntegrationsListResponseDataConnectedAccount.from_dict(
                    cast(dict[str, Any], _v_connected_account)
                )
                if (_v_connected_account := data["connected_account"]) is not None
                else None,
                auth_methods=[
                    DataIntegrationsListResponseDataAuthMethods(item)
                    for item in cast(list[Any], _v_auth_methods)
                ]
                if (_v_auth_methods := data.get("auth_methods")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationsListResponseData", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["name"] = self.name
        if self.description is not None:
            result["description"] = self.description
        else:
            result["description"] = None
        result["slug"] = self.slug
        result["integration_type"] = self.integration_type
        result["credentials_type"] = self.credentials_type
        if self.scopes is not None:
            result["scopes"] = self.scopes
        else:
            result["scopes"] = None
        result["ownership"] = (
            self.ownership.value if isinstance(self.ownership, Enum) else self.ownership
        )
        result["created_at"] = self.created_at
        result["updated_at"] = self.updated_at
        if self.connected_account is not None:
            result["connected_account"] = self.connected_account.to_dict()
        else:
            result["connected_account"] = None
        if self.auth_methods is not None:
            result["auth_methods"] = [
                item.value if isinstance(item, Enum) else item
                for item in self.auth_methods
            ]
        return result
