"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .webhookeventtype import WebhookEventType
from .webhookstatus import WebhookStatus
from datetime import datetime
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class WebhookTypedDict(TypedDict):
    r"""A configured webhook endpoint that receives event notifications."""

    webhook_id: str
    r"""Unique identifier for the webhook."""
    url: str
    r"""The URL where webhook events will be sent."""
    status: WebhookStatus
    r"""The status of a webhook."""
    event_types: List[WebhookEventType]
    r"""The list of event types this webhook is subscribed to."""
    description: str
    r"""A description of the webhook for reference."""
    created_on: datetime
    r"""Timestamp of when the webhook was created."""
    updated_on: datetime
    r"""Timestamp of when the webhook was last updated."""
    last_used_on: NotRequired[datetime]
    r"""Timestamp of when the webhook last received an event."""


class Webhook(BaseModel):
    r"""A configured webhook endpoint that receives event notifications."""

    webhook_id: Annotated[str, pydantic.Field(alias="webhookID")]
    r"""Unique identifier for the webhook."""

    url: str
    r"""The URL where webhook events will be sent."""

    status: WebhookStatus
    r"""The status of a webhook."""

    event_types: Annotated[List[WebhookEventType], pydantic.Field(alias="eventTypes")]
    r"""The list of event types this webhook is subscribed to."""

    description: str
    r"""A description of the webhook for reference."""

    created_on: Annotated[datetime, pydantic.Field(alias="createdOn")]
    r"""Timestamp of when the webhook was created."""

    updated_on: Annotated[datetime, pydantic.Field(alias="updatedOn")]
    r"""Timestamp of when the webhook was last updated."""

    last_used_on: Annotated[Optional[datetime], pydantic.Field(alias="lastUsedOn")] = (
        None
    )
    r"""Timestamp of when the webhook last received an event."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["lastUsedOn"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    Webhook.model_rebuild()
except NameError:
    pass
