"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 90f838fcce7a

from __future__ import annotations
from .mode import Mode
from .url import URL, URLTypedDict
from .webhook_event_types import WebhookEventTypes
from .webhook_status import WebhookStatus
from mollie import models
from mollie.types import BaseModel, Nullable, UNSET_SENTINEL
import pydantic
from pydantic import field_serializer, model_serializer
from typing import List
from typing_extensions import Annotated, TypedDict


class CreateWebhookLinksTypedDict(TypedDict):
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    self_: URLTypedDict
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""
    documentation: URLTypedDict
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""


class CreateWebhookLinks(BaseModel):
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    self_: Annotated[URL, pydantic.Field(alias="self")]
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""

    documentation: URL
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""


class CreateWebhookTypedDict(TypedDict):
    resource: str
    r"""Indicates the response contains a webhook subscription object. Will always contain the string `webhook` for this endpoint."""
    id: str
    r"""The identifier uniquely referring to this subscription."""
    url: str
    r"""The subscription's events destination."""
    profile_id: Nullable[str]
    r"""The identifier uniquely referring to the profile that created the subscription."""
    created_at: str
    r"""The subscription's date time of creation."""
    name: str
    r"""The subscription's name."""
    event_types: List[WebhookEventTypes]
    r"""The events types that are subscribed."""
    status: WebhookStatus
    r"""The subscription's current status."""
    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""
    webhook_secret: str
    r"""The subscription's secret."""
    links: CreateWebhookLinksTypedDict
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""


class CreateWebhook(BaseModel):
    resource: str
    r"""Indicates the response contains a webhook subscription object. Will always contain the string `webhook` for this endpoint."""

    id: str
    r"""The identifier uniquely referring to this subscription."""

    url: str
    r"""The subscription's events destination."""

    profile_id: Annotated[Nullable[str], pydantic.Field(alias="profileId")]
    r"""The identifier uniquely referring to the profile that created the subscription."""

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""The subscription's date time of creation."""

    name: str
    r"""The subscription's name."""

    event_types: Annotated[List[WebhookEventTypes], pydantic.Field(alias="eventTypes")]
    r"""The events types that are subscribed."""

    status: WebhookStatus
    r"""The subscription's current status."""

    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""

    webhook_secret: Annotated[str, pydantic.Field(alias="webhookSecret")]
    r"""The subscription's secret."""

    links: Annotated[CreateWebhookLinks, pydantic.Field(alias="_links")]
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.WebhookStatus(value)
            except ValueError:
                return value
        return value

    @field_serializer("mode")
    def serialize_mode(self, value):
        if isinstance(value, str):
            try:
                return models.Mode(value)
            except ValueError:
                return value
        return value

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        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:
                m[k] = val

        return m


try:
    CreateWebhookLinks.model_rebuild()
except NameError:
    pass
try:
    CreateWebhook.model_rebuild()
except NameError:
    pass
