# 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_input_type import (
    DataIntegrationCredentialsInputType,
)


@dataclass(slots=True)
class DataIntegrationCredentialsInput:
    """Data Integration Credentials Input model."""

    type: DataIntegrationCredentialsInputType
    """The credentials type. `custom` uses your own OAuth app credentials; `organization` has each organization supply its own credentials (configured per-organization)."""
    client_id: str | None = None
    """OAuth client ID for the provider app. Required when `type` is `custom`; omit for `organization`."""
    client_secret: str | None = None
    """OAuth client secret for the provider app. Required when `type` is `custom`; omit for `organization`."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationCredentialsInput:
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=DataIntegrationCredentialsInputType(data["type"]),
                client_id=data.get("client_id"),
                client_secret=data.get("client_secret"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationCredentialsInput", 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
        if self.client_secret is not None:
            result["client_secret"] = self.client_secret
        return result
