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

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 EventType, Visibility, WebhookEvent


class EventWebhook(BaseModel):
    webhook: Union[
        "EventWebhookWebhookWebhookPayload",
        "EventWebhookWebhookEventCreated",
        "EventWebhookWebhookTicketEvent",
        "EventWebhookWebhookTrackerEvent",
    ] = Field(discriminator="typename__")


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


class EventWebhookWebhookEventCreated(BaseModel):
    typename__: Literal["EventCreated"] = Field(alias="__typename")
    uuid: str
    event: WebhookEvent
    date: Annotated[datetime, BeforeValidator(gql_time)]
    new_event: "EventWebhookWebhookEventCreatedNewEvent" = Field(alias="newEvent")


class EventWebhookWebhookEventCreatedNewEvent(BaseModel):
    ticket: "EventWebhookWebhookEventCreatedNewEventTicket"
    changes: list[
        Annotated[
            Union[
                "EventWebhookWebhookEventCreatedNewEventChangesEventDetail",
                "EventWebhookWebhookEventCreatedNewEventChangesComment",
            ],
            Field(discriminator="typename__"),
        ]
    ]


class EventWebhookWebhookEventCreatedNewEventTicket(BaseModel):
    id: int
    subject: str
    tracker: "EventWebhookWebhookEventCreatedNewEventTicketTracker"


class EventWebhookWebhookEventCreatedNewEventTicketTracker(BaseModel):
    id: int


class EventWebhookWebhookEventCreatedNewEventChangesEventDetail(BaseModel):
    typename__: Literal[
        "Assignment",
        "Created",
        "EventDetail",
        "LabelUpdate",
        "StatusChange",
        "TicketMention",
        "UserMention",
    ] = Field(alias="__typename")
    event_type: EventType = Field(alias="eventType")


class EventWebhookWebhookEventCreatedNewEventChangesComment(BaseModel):
    typename__: Literal["Comment"] = Field(alias="__typename")
    event_type: EventType = Field(alias="eventType")
    author: Union[
        "EventWebhookWebhookEventCreatedNewEventChangesCommentAuthorEntity",
        "EventWebhookWebhookEventCreatedNewEventChangesCommentAuthorEmailAddress",
        "EventWebhookWebhookEventCreatedNewEventChangesCommentAuthorExternalUser",
        "EventWebhookWebhookEventCreatedNewEventChangesCommentAuthorUser",
    ] = Field(discriminator="typename__")


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


class EventWebhookWebhookEventCreatedNewEventChangesCommentAuthorEmailAddress(
    BaseModel
):
    typename__: Literal["EmailAddress"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    mailbox: str
    name: Optional[str]


class EventWebhookWebhookEventCreatedNewEventChangesCommentAuthorExternalUser(
    BaseModel
):
    typename__: Literal["ExternalUser"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    external_id: str = Field(alias="externalId")
    external_url: Optional[str] = Field(alias="externalUrl")


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


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


class EventWebhookWebhookTicketEventTicket(BaseModel):
    id: int
    subject: str
    tracker: "EventWebhookWebhookTicketEventTicketTracker"
    submitter: Union[
        "EventWebhookWebhookTicketEventTicketSubmitterEntity",
        "EventWebhookWebhookTicketEventTicketSubmitterEmailAddress",
        "EventWebhookWebhookTicketEventTicketSubmitterExternalUser",
        "EventWebhookWebhookTicketEventTicketSubmitterUser",
    ] = Field(discriminator="typename__")


class EventWebhookWebhookTicketEventTicketTracker(BaseModel):
    id: int
    name: str


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


class EventWebhookWebhookTicketEventTicketSubmitterEmailAddress(BaseModel):
    typename__: Literal["EmailAddress"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    mailbox: str
    name: Optional[str]


class EventWebhookWebhookTicketEventTicketSubmitterExternalUser(BaseModel):
    typename__: Literal["ExternalUser"] = Field(alias="__typename")
    canonical_name: str = Field(alias="canonicalName")
    external_id: str = Field(alias="externalId")
    external_url: Optional[str] = Field(alias="externalUrl")


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


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


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


EventWebhook.model_rebuild()
EventWebhookWebhookEventCreated.model_rebuild()
EventWebhookWebhookEventCreatedNewEvent.model_rebuild()
EventWebhookWebhookEventCreatedNewEventTicket.model_rebuild()
EventWebhookWebhookEventCreatedNewEventChangesComment.model_rebuild()
EventWebhookWebhookTicketEvent.model_rebuild()
EventWebhookWebhookTicketEventTicket.model_rebuild()
EventWebhookWebhookTrackerEvent.model_rebuild()
