# 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_integration_credentials_response_error import (
    DataIntegrationCredentialsResponseError,
)

from .data_integration_credentials_response_credential import (
    DataIntegrationCredentialsResponseCredential,
)


@dataclass(slots=True)
class DataIntegrationCredentialsResponse:
    """Data Integration Credentials Response model."""

    active: Literal[True] | None = None
    """Indicates credentials are available."""
    credential: DataIntegrationCredentialsResponseCredential | None = None
    """The credential object containing the vended secret."""
    error: DataIntegrationCredentialsResponseError | None = None
    """The reason credentials are unavailable. Additional values may be added in the future; handle unknown values gracefully.
- `"not_installed"`: The user does not have the integration installed.
- `"needs_reauthorization"`: The user needs to reauthorize the integration."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationCredentialsResponse:
        """Deserialize from a dictionary."""
        try:
            return cls(
                active=data.get("active"),
                credential=DataIntegrationCredentialsResponseCredential.from_dict(
                    cast(dict[str, Any], _v_credential)
                )
                if (_v_credential := data.get("credential")) is not None
                else None,
                error=DataIntegrationCredentialsResponseError(_v_error)
                if (_v_error := data.get("error")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationCredentialsResponse", e)

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