# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

import pydantic
import typing_extensions
from ...core.pydantic_utilities import IS_PYDANTIC_V2
from ...core.serialization import FieldMetadata
from ...core.unchecked_base_model import UncheckedBaseModel
from .webhook_status import WebhookStatus
from .webhook_subscription_populated import WebhookSubscriptionPopulated


class Webhook(UncheckedBaseModel):
    id: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="_id"),
        pydantic.Field(alias="_id", description="The unique identifier for the webhook"),
    ] = None
    url: typing.Optional[str] = pydantic.Field(default=None)
    """
    The webhook endpoint URL
    """

    description: typing.Optional[str] = pydantic.Field(default=None)
    """
    The description of the webhook
    """

    status: typing.Optional[WebhookStatus] = pydantic.Field(default=None)
    """
    The status of the webhook
    """

    organization_id: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="organizationId"),
        pydantic.Field(alias="organizationId", description="The organization ID"),
    ] = None
    created_by: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="createdBy"),
        pydantic.Field(alias="createdBy", description="The user ID who created the webhook"),
    ] = None
    subscriptions: typing.Optional[typing.List[WebhookSubscriptionPopulated]] = pydantic.Field(default=None)
    """
    A list of subscriptions for the webhook with populated agent details.
    """

    decrypted_secret_key: typing_extensions.Annotated[
        typing.Optional[str],
        FieldMetadata(alias="decryptedSecretKey"),
        pydantic.Field(
            alias="decryptedSecretKey",
            description="The decrypted signing secret for the webhook. This is only returned when fetching a single webhook by ID.",
        ),
    ] = None
    created_at: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="createdAt"),
        pydantic.Field(alias="createdAt", description="The date and time when the webhook was created"),
    ] = None
    updated_at: typing_extensions.Annotated[
        typing.Optional[dt.datetime],
        FieldMetadata(alias="updatedAt"),
        pydantic.Field(alias="updatedAt", description="The date and time when the webhook was last updated"),
    ] = None

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
