# 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 DataIntegrationInstallation:
    """Data Integration Installation model."""

    id: str
    """Unique identifier of the installation."""
    user_id: str
    """The User the API key was installed for."""
    organization_id: str | None
    """The Organization the installation is scoped to, or null when unscoped."""
    api_key_last_4: str | None
    """The last four characters of the stored API key. The full key is never returned."""

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

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