# 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_credential_type import (
    DataIntegrationCredentialType,
)


@dataclass(slots=True)
class DataIntegrationCredential:
    """The credentials configured for the Data Integration."""

    type: DataIntegrationCredentialType
    """The credentials type. `custom` uses your own OAuth app credentials; `organization` has each organization supply its own credentials (so `client_id`/`redacted_client_secret` are null on the integration itself)."""
    client_id: str | None
    """The OAuth client ID configured for the provider app. Null for `organization` credentials."""
    redacted_client_secret: str | None
    """The last four characters of the OAuth client secret. The full secret is never returned. Null for `organization` credentials."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationCredential:
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=DataIntegrationCredentialType(data["type"]),
                client_id=data["client_id"],
                redacted_client_secret=data["redacted_client_secret"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationCredential", e)

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