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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime


@dataclass(slots=True)
class DirectoryGroup:
    """Directory Group model."""

    object: Literal["directory_group"]
    """Distinguishes the Directory Group object."""
    id: str
    """Unique identifier for the Directory Group."""
    idp_id: str
    """Unique identifier for the group, assigned by the Directory Provider. Different Directory Providers use different ID formats."""
    directory_id: str
    """The identifier of the Directory the Directory Group belongs to."""
    organization_id: str
    """The identifier for the Organization in which the Directory resides."""
    name: str
    """The name of the Directory Group."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    raw_attributes: Optional[Dict[str, Any]] = None
    """The raw attributes received from the directory provider."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "DirectoryGroup":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "directory_group"),
                id=data["id"],
                idp_id=data["idp_id"],
                directory_id=data["directory_id"],
                organization_id=data["organization_id"],
                name=data["name"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                raw_attributes=data.get("raw_attributes"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DirectoryGroup", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["idp_id"] = self.idp_id
        result["directory_id"] = self.directory_id
        result["organization_id"] = self.organization_id
        result["name"] = self.name
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        if self.raw_attributes is not None:
            result["raw_attributes"] = self.raw_attributes
        return result
