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

from __future__ import annotations

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

from workos._types import _raise_deserialize_error

from .data_integration_credentials import DataIntegrationCredentials


@dataclass(slots=True)
class DataIntegrationConfigurationResponse:
    """Data Integration Configuration Response model."""

    object: Literal["data_integration_configuration"]
    """Distinguishes the data integration configuration object."""
    id: str
    """The unique identifier of the data integration."""
    organization_id: str
    """The [Organization](https://workos.com/docs/reference/organization) this configuration applies to."""
    slug: str
    """The slug identifier of the provider (e.g., `github`, `slack`, `notion`)."""
    name: str
    """The display name of the data integration."""
    enabled: bool
    """Whether the integration is enabled for this organization. Reflects the organization override when one exists, otherwise the provider default."""
    scopes: list[str] | None
    """The OAuth scopes in effect for this organization. Reflects the organization override when one is set, otherwise the provider scopes, or `null` when none are configured."""
    config: dict[str, str]
    """The provider-specific config values in effect for this organization, keyed by config field. Reflects the organization override for organization-credential providers, otherwise the provider root. Empty when none are configured."""
    created_at: str
    """The timestamp when the configuration was created."""
    updated_at: str
    """The timestamp when the configuration was last updated."""
    credentials: DataIntegrationCredentials | None = None

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationConfigurationResponse:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "data_integration_configuration"),
                id=data["id"],
                organization_id=data["organization_id"],
                slug=data["slug"],
                name=data["name"],
                enabled=data["enabled"],
                scopes=data["scopes"],
                config=data["config"],
                created_at=data["created_at"],
                updated_at=data["updated_at"],
                credentials=DataIntegrationCredentials.from_dict(
                    cast(dict[str, Any], _v_credentials)
                )
                if (_v_credentials := data.get("credentials")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationConfigurationResponse", 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["organization_id"] = self.organization_id
        result["slug"] = self.slug
        result["name"] = self.name
        result["enabled"] = self.enabled
        if self.scopes is not None:
            result["scopes"] = self.scopes
        else:
            result["scopes"] = None
        result["config"] = self.config
        result["created_at"] = self.created_at
        result["updated_at"] = self.updated_at
        if self.credentials is not None:
            result["credentials"] = self.credentials.to_dict()
        return result
