# 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

from workos._types import _raise_deserialize_error
from workos.common.models.user_identities_get_item_provider import (
    UserIdentitiesGetItemProvider,
)


@dataclass(slots=True)
class UserIdentitiesGetItem:
    """User Identities Get Item model."""

    idp_id: str
    """The unique ID of the user in the external identity provider."""
    type: Literal["OAuth"]
    """The type of the identity."""
    provider: UserIdentitiesGetItemProvider
    """The type of OAuth provider for the identity."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> UserIdentitiesGetItem:
        """Deserialize from a dictionary."""
        try:
            return cls(
                idp_id=data["idp_id"],
                type=data.get("type", "OAuth"),
                provider=UserIdentitiesGetItemProvider(data["provider"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("UserIdentitiesGetItem", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["idp_id"] = self.idp_id
        result["type"] = self.type
        result["provider"] = (
            self.provider.value if isinstance(self.provider, Enum) else self.provider
        )
        return result
