# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class DataIntegrationsUpsertApiKeyRequest:
    """Data Integrations Upsert Api Key Request model."""

    user_id: str
    """A [User](https://workos.com/docs/reference/authkit/user) identifier."""
    secret: str
    """The API key secret to store for this integration."""
    organization_id: str | None = None
    """An [Organization](https://workos.com/docs/reference/organization) identifier. Optional parameter to scope the connection to a specific organization."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DataIntegrationsUpsertApiKeyRequest:
        """Deserialize from a dictionary."""
        try:
            return cls(
                user_id=data["user_id"],
                secret=data["secret"],
                organization_id=data.get("organization_id"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationsUpsertApiKeyRequest", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["user_id"] = self.user_id
        result["secret"] = self.secret
        if self.organization_id is not None:
            result["organization_id"] = self.organization_id
        return result
