# Generated by ariadne-codegen
# Source: exponent/core/graphql/operations

from typing import Any, Optional, Union
from uuid import UUID

from .base_client import AsyncBaseClient
from .base_model import UNSET, UnsetType
from .chats import Chats
from .create_cloud_chat_from_repository import CreateCloudChatFromRepository
from .enable_cloud_repository import EnableCloudRepository
from .github_repositories import GithubRepositories
from .halt_chat_stream import HaltChatStream
from .input_types import ChatConfig, ChatInput, ChatResourceConfigInput, RepositoryInput
from .rebuild_cloud_repository import RebuildCloudRepository
from .refresh_api_key import RefreshApiKey
from .report_sandbox_info import ReportSandboxInfo
from .set_login_complete import SetLoginComplete
from .start_chat_turn import StartChatTurn


def gql(q: str) -> str:
    return q


class IndentGraphQLClient(AsyncBaseClient):
    async def chats(self, **kwargs: Any) -> Chats:
        query = gql("""
            query Chats {
              chats {
                __typename
                ... on UnauthenticatedError {
                  message
                }
                ... on Chats {
                  chats {
                    chatUuid
                    name
                    subtitle
                    isShared
                    isStarted
                    updatedAt
                    prStatus {
                      __typename
                      ... on PRInfo {
                        number
                        title
                        status
                      }
                    }
                  }
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = await self.execute(
            query=query, operation_name="Chats", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return Chats.model_validate(data)

    async def create_cloud_chat_from_repository(
        self, resource_config: ChatResourceConfigInput, **kwargs: Any
    ) -> CreateCloudChatFromRepository:
        query = gql("""
            mutation CreateCloudChatFromRepository($resourceConfig: ChatResourceConfigInput!) {
              createChatWithResourceConfig(input: {resourceConfig: $resourceConfig}) {
                __typename
                ... on Chat {
                  chatUuid
                }
                ... on UnauthenticatedError {
                  message
                }
                ... on NotFoundError {
                  resourceType
                  resourceId
                  message
                }
                ... on InputValidationError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {"resourceConfig": resource_config}
        response = await self.execute(
            query=query,
            operation_name="CreateCloudChatFromRepository",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return CreateCloudChatFromRepository.model_validate(data)

    async def enable_cloud_repository(
        self, repositories: list[RepositoryInput], **kwargs: Any
    ) -> EnableCloudRepository:
        query = gql("""
            mutation EnableCloudRepository($repositories: [RepositoryInput!]!) {
              enableCloudRepository(input: {repositories: $repositories}) {
                __typename
                ... on EnableCloudRepositoriesResult {
                  results {
                    orgName
                    repoName
                    success
                    errorMessage
                    images {
                      buildRef
                      createdAt
                      updatedAt
                    }
                  }
                }
                ... on UnauthenticatedError {
                  message
                }
                ... on NotFoundError {
                  resourceType
                  resourceId
                  message
                }
                ... on CloudSessionError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {"repositories": repositories}
        response = await self.execute(
            query=query,
            operation_name="EnableCloudRepository",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return EnableCloudRepository.model_validate(data)

    async def github_repositories(self, **kwargs: Any) -> GithubRepositories:
        query = gql("""
            query GithubRepositories {
              githubRepositories {
                __typename
                ... on Repositories {
                  repositories {
                    uuid: repositoryUuid
                    githubOrgName
                    githubRepoName
                    createdAt
                    updatedAt
                  }
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = await self.execute(
            query=query,
            operation_name="GithubRepositories",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GithubRepositories.model_validate(data)

    async def halt_chat_stream(self, chat_uuid: UUID, **kwargs: Any) -> HaltChatStream:
        query = gql("""
            mutation HaltChatStream($chatUuid: UUID!) {
              haltChatStream(input: {chatUuid: $chatUuid}) {
                __typename
                ... on Chat {
                  chatUuid
                }
                ... on UnauthenticatedError {
                  message
                }
                ... on NotFoundError {
                  resourceType
                  resourceId
                  message
                }
                ... on RemoteExecutionError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {"chatUuid": chat_uuid}
        response = await self.execute(
            query=query, operation_name="HaltChatStream", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return HaltChatStream.model_validate(data)

    async def rebuild_cloud_repository(
        self, repository_uuid: UUID, **kwargs: Any
    ) -> RebuildCloudRepository:
        query = gql("""
            mutation RebuildCloudRepository($repositoryUuid: UUID!) {
              rebuildCloudRepository(input: {repositoryUuid: $repositoryUuid}) {
                __typename
                ... on ContainerImages {
                  images {
                    buildRef
                    createdAt
                    updatedAt
                  }
                }
                ... on UnauthenticatedError {
                  message
                }
                ... on NotFoundError {
                  resourceType
                  resourceId
                  message
                }
                ... on CloudSessionError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {"repositoryUuid": repository_uuid}
        response = await self.execute(
            query=query,
            operation_name="RebuildCloudRepository",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return RebuildCloudRepository.model_validate(data)

    async def refresh_api_key(self, **kwargs: Any) -> RefreshApiKey:
        query = gql("""
            mutation RefreshApiKey {
              refreshApiKey(input: {}) {
                __typename
                ... on User {
                  userApiKey
                }
                ... on UnauthenticatedError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = await self.execute(
            query=query, operation_name="RefreshApiKey", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return RefreshApiKey.model_validate(data)

    async def report_sandbox_info(
        self,
        sandbox_id: str,
        disk_usage_gb: Union[Optional[float], UnsetType] = UNSET,
        indent_log_file: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> ReportSandboxInfo:
        query = gql("""
            mutation ReportSandboxInfo($sandboxId: String!, $diskUsageGb: Float, $indentLogFile: String) {
              reportSandboxInfo(
                input: {sandboxId: $sandboxId, diskUsageGb: $diskUsageGb, indentLogFile: $indentLogFile}
              ) {
                __typename
                ... on SandboxInfoResponse {
                  success
                  message
                }
                ... on UnauthenticatedError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {
            "sandboxId": sandbox_id,
            "diskUsageGb": disk_usage_gb,
            "indentLogFile": indent_log_file,
        }
        response = await self.execute(
            query=query,
            operation_name="ReportSandboxInfo",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return ReportSandboxInfo.model_validate(data)

    async def set_login_complete(self, **kwargs: Any) -> SetLoginComplete:
        query = gql("""
            mutation SetLoginComplete {
              setLoginComplete(input: {}) {
                __typename
                ... on User {
                  userApiKey
                }
                ... on UnauthenticatedError {
                  message
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = await self.execute(
            query=query,
            operation_name="SetLoginComplete",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return SetLoginComplete.model_validate(data)

    async def start_chat_turn(
        self,
        chat_input: ChatInput,
        chat_config: ChatConfig,
        parent_uuid: Union[Optional[UUID], UnsetType] = UNSET,
        **kwargs: Any
    ) -> StartChatTurn:
        query = gql("""
            mutation StartChatTurn($chatInput: ChatInput!, $parentUuid: UUID, $chatConfig: ChatConfig!) {
              startChatTurn(
                input: {chatInput: $chatInput, parentUuid: $parentUuid, chatConfig: $chatConfig}
              ) {
                __typename
                ... on UnauthenticatedError {
                  message
                }
                ... on NotFoundError {
                  resourceType
                  resourceId
                  message
                }
                ... on Chat {
                  chatUuid
                }
              }
            }
            """)
        variables: dict[str, object] = {
            "chatInput": chat_input,
            "parentUuid": parent_uuid,
            "chatConfig": chat_config,
        }
        response = await self.execute(
            query=query, operation_name="StartChatTurn", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return StartChatTurn.model_validate(data)
