# 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

from workos._types import _raise_deserialize_error
from workos.common.models.data_integration_credentials_credentials_type import (
    DataIntegrationCredentialsCredentialsType,
)


@dataclass(slots=True)
class DataIntegrationCredentials:
    """Organization-managed OAuth credential configuration. Present only for integrations whose credentials are supplied by the organization; absent otherwise."""

    credentials_type: DataIntegrationCredentialsCredentialsType
    """The credentials type for this integration (e.g., `shared`, `custom`, or `organization`)."""
    has_credentials: bool
    """Whether the organization has supplied OAuth credentials for this integration."""
    client_id: str | None
    """The OAuth client ID supplied by the organization, or `null` when none is configured."""
    client_secret_last_four: str | None
    """The last four characters of the organization-supplied OAuth client secret, or `null` when none is configured."""
    redirect_uri: str
    """The redirect URI to register with the provider when configuring the organization-managed OAuth application."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationCredentials:
        """Deserialize from a dictionary."""
        try:
            return cls(
                credentials_type=DataIntegrationCredentialsCredentialsType(
                    data["credentials_type"]
                ),
                has_credentials=data["has_credentials"],
                client_id=data["client_id"],
                client_secret_last_four=data["client_secret_last_four"],
                redirect_uri=data["redirect_uri"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationCredentials", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["credentials_type"] = (
            self.credentials_type.value
            if isinstance(self.credentials_type, Enum)
            else self.credentials_type
        )
        result["has_credentials"] = self.has_credentials
        if self.client_id is not None:
            result["client_id"] = self.client_id
        else:
            result["client_id"] = None
        if self.client_secret_last_four is not None:
            result["client_secret_last_four"] = self.client_secret_last_four
        else:
            result["client_secret_last_four"] = None
        result["redirect_uri"] = self.redirect_uri
        return result
