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

from __future__ import annotations

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


@dataclass(slots=True)
class CreateM2MApplication:
    """Create M2M Application model."""

    name: str
    """The name of the application."""
    application_type: Literal["m2m"]
    """The type of application to create."""
    organization_id: str
    """The organization ID this application belongs to."""
    description: Optional[str] = None
    """A description for the application."""
    scopes: Optional[List[str]] = None
    """The OAuth scopes granted to the application."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "CreateM2MApplication":
        """Deserialize from a dictionary."""
        try:
            return cls(
                name=data["name"],
                application_type=data.get("application_type", "m2m"),
                organization_id=data["organization_id"],
                description=data.get("description"),
                scopes=data.get("scopes"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("CreateM2MApplication", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["name"] = self.name
        result["application_type"] = self.application_type
        result["organization_id"] = self.organization_id
        if self.description is not None:
            result["description"] = self.description
        else:
            result["description"] = None
        if self.scopes is not None:
            result["scopes"] = self.scopes
        else:
            result["scopes"] = None
        return result
