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

from __future__ import annotations

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

from .redirect_uri_input import RedirectUriInput


@dataclass(slots=True)
class UpdateOAuthApplication:
    """Update O Auth Application model."""

    name: Optional[str] = None
    """The name of the application."""
    description: Optional[str] = None
    """A description for the application."""
    scopes: Optional[List[str]] = None
    """The OAuth scopes granted to the application."""
    redirect_uris: Optional[List["RedirectUriInput"]] = None
    """Updated redirect URIs for the application. OAuth applications only."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "UpdateOAuthApplication":
        """Deserialize from a dictionary."""
        try:
            return cls(
                name=data.get("name"),
                description=data.get("description"),
                scopes=data.get("scopes"),
                redirect_uris=[
                    RedirectUriInput.from_dict(cast(Dict[str, Any], item))
                    for item in cast(list[Any], _v_redirect_uris)
                ]
                if (_v_redirect_uris := data.get("redirect_uris")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("UpdateOAuthApplication", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        if self.name is not None:
            result["name"] = self.name
        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
        if self.redirect_uris is not None:
            result["redirect_uris"] = [item.to_dict() for item in self.redirect_uris]
        else:
            result["redirect_uris"] = None
        return result
