# Generated by ariadne-codegen
# Source: gitsrht/graphql/

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

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

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


class GetRepoAccessSettings(BaseModel):
    user: Optional["GetRepoAccessSettingsUser"]


class GetRepoAccessSettingsUser(BaseModel):
    canonical_name: str = Field(alias="canonicalName")
    username: str
    repository: Optional["GetRepoAccessSettingsUserRepository"]


class GetRepoAccessSettingsUserRepository(BaseModel):
    rid: str
    name: str
    visibility: Visibility
    owner: "GetRepoAccessSettingsUserRepositoryOwner"
    acls: "GetRepoAccessSettingsUserRepositoryAcls"
    deploy_keys: "GetRepoAccessSettingsUserRepositoryDeployKeys" = Field(
        alias="deployKeys"
    )


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


class GetRepoAccessSettingsUserRepositoryAcls(BaseModel):
    cursor: Optional[Any]
    results: list["GetRepoAccessSettingsUserRepositoryAclsResults"]


class GetRepoAccessSettingsUserRepositoryAclsResults(BaseModel):
    id: int
    created: Annotated[datetime, BeforeValidator(gql_time)]
    mode: Optional[AccessMode]
    entity: Union[
        "GetRepoAccessSettingsUserRepositoryAclsResultsEntityEntity",
        "GetRepoAccessSettingsUserRepositoryAclsResultsEntityUser",
    ] = Field(discriminator="typename__")


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


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


class GetRepoAccessSettingsUserRepositoryDeployKeys(BaseModel):
    cursor: Optional[Any]
    results: list["GetRepoAccessSettingsUserRepositoryDeployKeysResults"]


class GetRepoAccessSettingsUserRepositoryDeployKeysResults(BaseModel):
    rid: str
    key: str
    key_type: str = Field(alias="keyType")
    fingerprint_sha_256: str = Field(alias="fingerprintSHA256")
    comment: Optional[str]
    created: Annotated[datetime, BeforeValidator(gql_time)]
    last_used: Optional[Annotated[datetime, BeforeValidator(gql_time)]] = Field(
        alias="lastUsed"
    )
    access: AccessMode


GetRepoAccessSettings.model_rebuild()
GetRepoAccessSettingsUser.model_rebuild()
GetRepoAccessSettingsUserRepository.model_rebuild()
GetRepoAccessSettingsUserRepositoryAcls.model_rebuild()
GetRepoAccessSettingsUserRepositoryAclsResults.model_rebuild()
GetRepoAccessSettingsUserRepositoryDeployKeys.model_rebuild()
