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

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import cast
from typing import Any, Dict, List, Optional
from workos._types import _raise_deserialize_error
from workos.common.models.update_webhook_endpoint_events import (
    UpdateWebhookEndpointEvents,
)
from workos.common.models.update_webhook_endpoint_status import (
    UpdateWebhookEndpointStatus,
)


@dataclass(slots=True)
class UpdateWebhookEndpoint:
    """Update Webhook Endpoint model."""

    endpoint_url: Optional[str] = None
    """The HTTPS URL where webhooks will be sent."""
    status: Optional["UpdateWebhookEndpointStatus"] = None
    """Whether the Webhook Endpoint is enabled or disabled."""
    events: Optional[List["UpdateWebhookEndpointEvents"]] = None
    """The events that the Webhook Endpoint is subscribed to."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "UpdateWebhookEndpoint":
        """Deserialize from a dictionary."""
        try:
            return cls(
                endpoint_url=data.get("endpoint_url"),
                status=UpdateWebhookEndpointStatus(_v_status)
                if (_v_status := data.get("status")) is not None
                else None,
                events=[
                    UpdateWebhookEndpointEvents(item)
                    for item in cast(list[Any], _v_events)
                ]
                if (_v_events := data.get("events")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("UpdateWebhookEndpoint", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        if self.endpoint_url is not None:
            result["endpoint_url"] = self.endpoint_url
        if self.status is not None:
            result["status"] = (
                self.status.value if isinstance(self.status, Enum) else self.status
            )
        if self.events is not None:
            result["events"] = [
                item.value if isinstance(item, Enum) else item for item in self.events
            ]
        return result
