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

from __future__ import annotations
from apideck_unify import models, utils
from apideck_unify.types import BaseModel
from apideck_unify.utils import validate_open_enum
from enum import Enum
from pydantic import field_serializer
from pydantic.functional_validators import PlainValidator
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class EventSource(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Unify event source"""

    NATIVE = "native"
    VIRTUAL = "virtual"


class ConnectorEventTypedDict(TypedDict):
    r"""Unify event that is supported on the connector. Events are delivered via Webhooks."""

    event_type: NotRequired[str]
    r"""Unify event type"""
    event_source: NotRequired[EventSource]
    r"""Unify event source"""
    downstream_event_type: NotRequired[str]
    r"""Downstream event type"""
    resources: NotRequired[List[str]]
    entity_type: NotRequired[str]
    r"""Unify entity type"""


class ConnectorEvent(BaseModel):
    r"""Unify event that is supported on the connector. Events are delivered via Webhooks."""

    event_type: Optional[str] = None
    r"""Unify event type"""

    event_source: Annotated[
        Optional[EventSource], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Unify event source"""

    downstream_event_type: Optional[str] = None
    r"""Downstream event type"""

    resources: Optional[List[str]] = None

    entity_type: Optional[str] = None
    r"""Unify entity type"""

    @field_serializer("event_source")
    def serialize_event_source(self, value):
        if isinstance(value, str):
            try:
                return models.EventSource(value)
            except ValueError:
                return value
        return value
