# 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_custom_provider_authenticate_via import (
    DataIntegrationCustomProviderAuthenticateVia,
)


@dataclass(slots=True)
class DataIntegrationCustomProvider:
    """Data Integration Custom Provider model."""

    name: str
    """A descriptive name for the custom provider."""
    authorization_url: str | None
    """The provider's OAuth authorization endpoint."""
    token_url: str | None
    """The provider's OAuth token endpoint."""
    refresh_token_url: str | None
    """The endpoint used to refresh tokens, if different from the token endpoint."""
    pkce_enabled: bool
    """Whether PKCE is used during the authorization code flow."""
    request_scope_separator: str
    """The separator used to join requested scopes."""
    scopes_required: bool
    """Whether at least one scope must be selected when connecting an account."""
    client_secret_required: bool
    """Whether a client secret is required for this provider."""
    additional_authorization_parameters: dict[str, str]
    """Additional static query parameters appended to the authorization request."""
    token_body_content_type: str
    """The Content-Type used when exchanging the token request."""
    authenticate_via: DataIntegrationCustomProviderAuthenticateVia
    """How client credentials are sent when exchanging authorization codes and refreshing tokens."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationCustomProvider:
        """Deserialize from a dictionary."""
        try:
            return cls(
                name=data["name"],
                authorization_url=data["authorization_url"],
                token_url=data["token_url"],
                refresh_token_url=data["refresh_token_url"],
                pkce_enabled=data["pkce_enabled"],
                request_scope_separator=data["request_scope_separator"],
                scopes_required=data["scopes_required"],
                client_secret_required=data["client_secret_required"],
                additional_authorization_parameters=data[
                    "additional_authorization_parameters"
                ],
                token_body_content_type=data["token_body_content_type"],
                authenticate_via=DataIntegrationCustomProviderAuthenticateVia(
                    data["authenticate_via"]
                ),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationCustomProvider", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["name"] = self.name
        if self.authorization_url is not None:
            result["authorization_url"] = self.authorization_url
        else:
            result["authorization_url"] = None
        if self.token_url is not None:
            result["token_url"] = self.token_url
        else:
            result["token_url"] = None
        if self.refresh_token_url is not None:
            result["refresh_token_url"] = self.refresh_token_url
        else:
            result["refresh_token_url"] = None
        result["pkce_enabled"] = self.pkce_enabled
        result["request_scope_separator"] = self.request_scope_separator
        result["scopes_required"] = self.scopes_required
        result["client_secret_required"] = self.client_secret_required
        result["additional_authorization_parameters"] = (
            self.additional_authorization_parameters
        )
        result["token_body_content_type"] = self.token_body_content_type
        result["authenticate_via"] = (
            self.authenticate_via.value
            if isinstance(self.authenticate_via, Enum)
            else self.authenticate_via
        )
        return result
