# 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, Literal

from workos._types import _format_datetime, _parse_datetime, _raise_deserialize_error


@dataclass(slots=True)
class ConnectApplicationM2M:
    """Connect Application M2M model."""

    object: Literal["connect_application"]
    """Distinguishes the connect application object."""
    id: str
    """The unique ID of the connect application."""
    client_id: str
    """The client ID of the connect application."""
    description: str | None
    """A description of the connect application."""
    name: str
    """The name of the connect application."""
    scopes: list[str]
    """The scopes available for this application."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    application_type: Literal["m2m"]
    """The type of the application."""
    organization_id: str
    """The ID of the organization the application belongs to."""

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