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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class DirectoryUserEmail:
    """Directory User Email model."""

    primary: Optional[bool] = None
    """Whether this is the primary email address."""
    type: Optional[str] = None
    """The type of email address."""
    value: Optional[str] = None
    """The email address value."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "DirectoryUserEmail":
        """Deserialize from a dictionary."""
        try:
            return cls(
                primary=data.get("primary"),
                type=data.get("type"),
                value=data.get("value"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DirectoryUserEmail", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        if self.primary is not None:
            result["primary"] = self.primary
        if self.type is not None:
            result["type"] = self.type
        if self.value is not None:
            result["value"] = self.value
        else:
            result["value"] = None
        return result
