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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Literal
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from workos.common.models.webhook_endpoint_status import WebhookEndpointStatus


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

    object: Literal["webhook_endpoint"]
    """Distinguishes the Webhook Endpoint object."""
    id: str
    """Unique identifier of the Webhook Endpoint."""
    endpoint_url: str
    """The URL to which webhooks are sent."""
    secret: str
    """The secret used to sign webhook payloads."""
    status: "WebhookEndpointStatus"
    """Whether the Webhook Endpoint is enabled or disabled."""
    events: List[str]
    """The events that the Webhook Endpoint is subscribed to."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "WebhookEndpoint":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "webhook_endpoint"),
                id=data["id"],
                endpoint_url=data["endpoint_url"],
                secret=data["secret"],
                status=WebhookEndpointStatus(data["status"]),
                events=data["events"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("WebhookEndpoint", 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["endpoint_url"] = self.endpoint_url
        result["secret"] = self.secret
        result["status"] = (
            self.status.value if isinstance(self.status, Enum) else self.status
        )
        result["events"] = self.events
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
