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

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",
        "EventWebhookWebhookGitEvent",
        "EventWebhookWebhookRepositoryEvent",
    ] = Field(discriminator="typename__")


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


class EventWebhookWebhookGitEvent(BaseModel):
    typename__: Literal["GitEvent"] = Field(alias="__typename")
    uuid: str
    event: WebhookEvent
    date: Annotated[datetime, BeforeValidator(gql_time)]
    pusher: Union[
        "EventWebhookWebhookGitEventPusherEntity",
        "EventWebhookWebhookGitEventPusherUser",
    ] = Field(discriminator="typename__")
    updates: list[Optional["EventWebhookWebhookGitEventUpdates"]]


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


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


class EventWebhookWebhookGitEventUpdates(BaseModel):
    old: Optional["EventWebhookWebhookGitEventUpdatesOld"]
    new: Optional[
        Annotated[
            Union[
                "EventWebhookWebhookGitEventUpdatesNewObject",
                "EventWebhookWebhookGitEventUpdatesNewCommit",
                "EventWebhookWebhookGitEventUpdatesNewTag",
            ],
            Field(discriminator="typename__"),
        ]
    ]
    log: Optional["EventWebhookWebhookGitEventUpdatesLog"]


class EventWebhookWebhookGitEventUpdatesOld(BaseModel):
    typename__: Literal["BinaryBlob", "Commit", "Object", "Tag", "TextBlob", "Tree"] = (
        Field(alias="__typename")
    )
    id: str


class EventWebhookWebhookGitEventUpdatesNewObject(BaseModel):
    typename__: Literal["BinaryBlob", "Object", "TextBlob", "Tree"] = Field(
        alias="__typename"
    )
    id: str
    short_id: str = Field(alias="shortId")


class EventWebhookWebhookGitEventUpdatesNewCommit(BaseModel):
    typename__: Literal["Commit"] = Field(alias="__typename")
    id: str
    short_id: str = Field(alias="shortId")
    message: str


class EventWebhookWebhookGitEventUpdatesNewTag(BaseModel):
    typename__: Literal["Tag"] = Field(alias="__typename")
    id: str
    short_id: str = Field(alias="shortId")
    message: str


class EventWebhookWebhookGitEventUpdatesLog(BaseModel):
    results: list["EventWebhookWebhookGitEventUpdatesLogResults"]


class EventWebhookWebhookGitEventUpdatesLogResults(BaseModel):
    id: str
    message: str
    author: "EventWebhookWebhookGitEventUpdatesLogResultsAuthor"


class EventWebhookWebhookGitEventUpdatesLogResultsAuthor(BaseModel):
    name: str


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


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


EventWebhook.model_rebuild()
EventWebhookWebhookGitEvent.model_rebuild()
EventWebhookWebhookGitEventUpdates.model_rebuild()
EventWebhookWebhookGitEventUpdatesLog.model_rebuild()
EventWebhookWebhookGitEventUpdatesLogResults.model_rebuild()
EventWebhookWebhookRepositoryEvent.model_rebuild()
