# 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
from workos._types import _raise_deserialize_error
from workos.common.models.create_webhook_endpoint_events import (
    CreateWebhookEndpointEvents,
)


@dataclass(slots=True)
class CreateWebhookEndpoint:
    """Create Webhook Endpoint model."""

    endpoint_url: str
    """The HTTPS URL where webhooks will be sent."""
    events: List["CreateWebhookEndpointEvents"]
    """The events that the Webhook Endpoint is subscribed to."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "CreateWebhookEndpoint":
        """Deserialize from a dictionary."""
        try:
            return cls(
                endpoint_url=data["endpoint_url"],
                events=[
                    CreateWebhookEndpointEvents(item)
                    for item in cast(list[Any], data["events"])
                ],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("CreateWebhookEndpoint", e)

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