# Generated by ariadne-codegen
# Source: hubsrht/services/lists/

from datetime import datetime
from typing import Annotated, Literal, Optional, Union

from pydantic import BeforeValidator, Field
from srht.graphql import gql_time

from .base_model import BaseModel
from .enums import Visibility, WebhookEvent


class EventWebhook(BaseModel):
    webhook: Union[
        "EventWebhookWebhookWebhookPayload",
        "EventWebhookWebhookEmailEvent",
        "EventWebhookWebhookMailingListEvent",
        "EventWebhookWebhookPatchsetEvent",
    ] = Field(discriminator="typename__")


class EventWebhookWebhookWebhookPayload(BaseModel):
    typename__: Literal["WebhookPayload"] = Field(alias="__typename")
    uuid: str
    event: WebhookEvent
    date: Annotated[datetime, BeforeValidator(gql_time)]


class EventWebhookWebhookEmailEvent(BaseModel):
    typename__: Literal["EmailEvent"] = Field(alias="__typename")
    uuid: str
    event: WebhookEvent
    date: Annotated[datetime, BeforeValidator(gql_time)]
    email: "EventWebhookWebhookEmailEventEmail"


class EventWebhookWebhookEmailEventEmail(BaseModel):
    id: int
    mailing_list: "EventWebhookWebhookEmailEventEmailMailingList" = Field(
        alias="mailingList"
    )
    message_id: str = Field(alias="messageID")
    subject: str
    sender: Union[
        "EventWebhookWebhookEmailEventEmailSenderEntity",
        "EventWebhookWebhookEmailEventEmailSenderMailbox",
        "EventWebhookWebhookEmailEventEmailSenderUser",
    ] = Field(discriminator="typename__")
    patch: Optional["EventWebhookWebhookEmailEventEmailPatch"]
    patchset: Optional["EventWebhookWebhookEmailEventEmailPatchset"]


class EventWebhookWebhookEmailEventEmailMailingList(BaseModel):
    id: int


class EventWebhookWebhookEmailEventEmailSenderEntity(BaseModel):
    typename__: Literal["Entity"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")


class EventWebhookWebhookEmailEventEmailSenderMailbox(BaseModel):
    typename__: Literal["Mailbox"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    name: str


class EventWebhookWebhookEmailEventEmailSenderUser(BaseModel):
    typename__: Literal["User"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    username: str


class EventWebhookWebhookEmailEventEmailPatch(BaseModel):
    trailers: list["EventWebhookWebhookEmailEventEmailPatchTrailers"]


class EventWebhookWebhookEmailEventEmailPatchTrailers(BaseModel):
    name: str
    value: str


class EventWebhookWebhookEmailEventEmailPatchset(BaseModel):
    id: int


class EventWebhookWebhookMailingListEvent(BaseModel):
    typename__: Literal["MailingListEvent"] = Field(alias="__typename")
    uuid: str
    event: WebhookEvent
    date: Annotated[datetime, BeforeValidator(gql_time)]
    mailing_list: "EventWebhookWebhookMailingListEventMailingList" = Field(
        alias="mailingList"
    )


class EventWebhookWebhookMailingListEventMailingList(BaseModel):
    id: int
    rid: str
    name: str
    description: Optional[str]
    visibility: Visibility


class EventWebhookWebhookPatchsetEvent(BaseModel):
    typename__: Literal["PatchsetEvent"] = Field(alias="__typename")
    uuid: str
    event: WebhookEvent
    date: Annotated[datetime, BeforeValidator(gql_time)]
    patchset: "EventWebhookWebhookPatchsetEventPatchset"


class EventWebhookWebhookPatchsetEventPatchset(BaseModel):
    id: int
    subject: str
    prefix: Optional[str]
    version: int
    mailing_list: "EventWebhookWebhookPatchsetEventPatchsetMailingList" = Field(
        alias="mailingList"
    )
    thread: "EventWebhookWebhookPatchsetEventPatchsetThread"
    patches: "EventWebhookWebhookPatchsetEventPatchsetPatches"
    submitter: Union[
        "EventWebhookWebhookPatchsetEventPatchsetSubmitterEntity",
        "EventWebhookWebhookPatchsetEventPatchsetSubmitterMailbox",
        "EventWebhookWebhookPatchsetEventPatchsetSubmitterUser",
    ] = Field(discriminator="typename__")


class EventWebhookWebhookPatchsetEventPatchsetMailingList(BaseModel):
    id: int


class EventWebhookWebhookPatchsetEventPatchsetThread(BaseModel):
    root: "EventWebhookWebhookPatchsetEventPatchsetThreadRoot"


class EventWebhookWebhookPatchsetEventPatchsetThreadRoot(BaseModel):
    message_id: str = Field(alias="messageID")
    reply_to: list[str]


class EventWebhookWebhookPatchsetEventPatchsetPatches(BaseModel):
    results: list["EventWebhookWebhookPatchsetEventPatchsetPatchesResults"]


class EventWebhookWebhookPatchsetEventPatchsetPatchesResults(BaseModel):
    subject: str
    message_id: str = Field(alias="messageID")
    patchset: Optional["EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatchset"]
    sender: Union[
        "EventWebhookWebhookPatchsetEventPatchsetPatchesResultsSenderEntity",
        "EventWebhookWebhookPatchsetEventPatchsetPatchesResultsSenderMailbox",
        "EventWebhookWebhookPatchsetEventPatchsetPatchesResultsSenderUser",
    ] = Field(discriminator="typename__")
    patch: Optional["EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatch"]


class EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatchset(BaseModel):
    id: int


class EventWebhookWebhookPatchsetEventPatchsetPatchesResultsSenderEntity(BaseModel):
    typename__: Literal["Entity"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")


class EventWebhookWebhookPatchsetEventPatchsetPatchesResultsSenderMailbox(BaseModel):
    typename__: Literal["Mailbox"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    name: str


class EventWebhookWebhookPatchsetEventPatchsetPatchesResultsSenderUser(BaseModel):
    typename__: Literal["User"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    username: str


class EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatch(BaseModel):
    prefix: Optional[str]
    trailers: list[
        "EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatchTrailers"
    ]


class EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatchTrailers(BaseModel):
    name: str
    value: str


class EventWebhookWebhookPatchsetEventPatchsetSubmitterEntity(BaseModel):
    typename__: Literal["Entity"] = Field(alias="__typename")


class EventWebhookWebhookPatchsetEventPatchsetSubmitterMailbox(BaseModel):
    typename__: Literal["Mailbox"] = Field(alias="__typename")
    name: str
    address: str


class EventWebhookWebhookPatchsetEventPatchsetSubmitterUser(BaseModel):
    typename__: Literal["User"] = Field(alias="__typename")
    name: str
    address: str


EventWebhook.model_rebuild()
EventWebhookWebhookEmailEvent.model_rebuild()
EventWebhookWebhookEmailEventEmail.model_rebuild()
EventWebhookWebhookEmailEventEmailPatch.model_rebuild()
EventWebhookWebhookMailingListEvent.model_rebuild()
EventWebhookWebhookPatchsetEvent.model_rebuild()
EventWebhookWebhookPatchsetEventPatchset.model_rebuild()
EventWebhookWebhookPatchsetEventPatchsetThread.model_rebuild()
EventWebhookWebhookPatchsetEventPatchsetPatches.model_rebuild()
EventWebhookWebhookPatchsetEventPatchsetPatchesResults.model_rebuild()
EventWebhookWebhookPatchsetEventPatchsetPatchesResultsPatch.model_rebuild()
