# 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 Group:
    """Group model."""

    object: Literal["group"]
    """The Group object."""
    id: str
    """The unique ID of the Group."""
    organization_id: str
    """The ID of the Organization the Group belongs to."""
    name: str
    """The name of the Group."""
    description: Optional[str]
    """An optional description of the Group."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "Group":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "group"),
                id=data["id"],
                organization_id=data["organization_id"],
                name=data["name"],
                description=data["description"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("Group", 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["organization_id"] = self.organization_id
        result["name"] = self.name
        if self.description is not None:
            result["description"] = self.description
        else:
            result["description"] = None
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
