# Generated by ariadne-codegen
# Source: queries.gql

from typing import Any, Dict, Optional, Union

from .all_security_tickers import AllSecurityTickers
from .async_base_client_open_telemetry import AsyncBaseClientOpenTelemetry
from .base_model import UNSET, UnsetType
from .currencies import Currencies
from .currency import Currency
from .exchanges import Exchanges
from .input_types import (
    DividendsInput,
    OutstandingSharesInput,
    SecurityInput,
    SecurityQuotesInput,
    SplitsInput,
)
from .ping import Ping
from .search_security import SearchSecurity
from .security import Security
from .update_dividends import UpdateDividends
from .update_outstanding_shares import UpdateOutstandingShares
from .update_security import UpdateSecurity
from .update_security_quotes import UpdateSecurityQuotes
from .update_splits import UpdateSplits


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


class AscentradeClient(AsyncBaseClientOpenTelemetry):
    async def ping(self, **kwargs: Any) -> Ping:
        query = gql(
            """
            query Ping {
              ping
            }
            """
        )
        variables: Dict[str, object] = {}
        response = await self.execute(
            query=query, operation_name="Ping", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return Ping.model_validate(data)

    async def currencies(self, **kwargs: Any) -> Currencies:
        query = gql(
            """
            query Currencies {
              currencies {
                id
                name
                iso_code
                fractional_unit
                number_to_basic
              }
            }
            """
        )
        variables: Dict[str, object] = {}
        response = await self.execute(
            query=query, operation_name="Currencies", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return Currencies.model_validate(data)

    async def currency(self, id: int, **kwargs: Any) -> Currency:
        query = gql(
            """
            query Currency($id: Int!) {
              currency(id: $id) {
                id
                name
                iso_code
                fractional_unit
                number_to_basic
              }
            }
            """
        )
        variables: Dict[str, object] = {"id": id}
        response = await self.execute(
            query=query, operation_name="Currency", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return Currency.model_validate(data)

    async def exchanges(self, **kwargs: Any) -> Exchanges:
        query = gql(
            """
            query Exchanges {
              exchanges {
                id
                name
                country {
                  alpha3_code
                  name
                }
                currency {
                  name
                  iso_code
                }
                open_utc
                close_utc
              }
            }
            """
        )
        variables: Dict[str, object] = {}
        response = await self.execute(
            query=query, operation_name="Exchanges", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return Exchanges.model_validate(data)

    async def update_security(
        self, data: SecurityInput, **kwargs: Any
    ) -> UpdateSecurity:
        query = gql(
            """
            mutation UpdateSecurity($data: SecurityInput!) {
              updateSecurity(data: $data) {
                success
                error
              }
            }
            """
        )
        variables: Dict[str, object] = {"data": data}
        response = await self.execute(
            query=query, operation_name="UpdateSecurity", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return UpdateSecurity.model_validate(data)

    async def update_security_quotes(
        self, data: SecurityQuotesInput, **kwargs: Any
    ) -> UpdateSecurityQuotes:
        query = gql(
            """
            mutation UpdateSecurityQuotes($data: SecurityQuotesInput!) {
              updateSecurityQuotes(data: $data) {
                success
                error
              }
            }
            """
        )
        variables: Dict[str, object] = {"data": data}
        response = await self.execute(
            query=query,
            operation_name="UpdateSecurityQuotes",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return UpdateSecurityQuotes.model_validate(data)

    async def update_splits(self, data: SplitsInput, **kwargs: Any) -> UpdateSplits:
        query = gql(
            """
            mutation UpdateSplits($data: SplitsInput!) {
              updateSplits(data: $data) {
                success
                error
              }
            }
            """
        )
        variables: Dict[str, object] = {"data": data}
        response = await self.execute(
            query=query, operation_name="UpdateSplits", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return UpdateSplits.model_validate(data)

    async def update_dividends(
        self, data: DividendsInput, **kwargs: Any
    ) -> UpdateDividends:
        query = gql(
            """
            mutation UpdateDividends($data: DividendsInput!) {
              updateDividends(data: $data) {
                success
                error
              }
            }
            """
        )
        variables: Dict[str, object] = {"data": data}
        response = await self.execute(
            query=query, operation_name="UpdateDividends", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return UpdateDividends.model_validate(data)

    async def update_outstanding_shares(
        self, data: OutstandingSharesInput, **kwargs: Any
    ) -> UpdateOutstandingShares:
        query = gql(
            """
            mutation UpdateOutstandingShares($data: OutstandingSharesInput!) {
              updateOutstandingShares(data: $data) {
                success
                error
              }
            }
            """
        )
        variables: Dict[str, object] = {"data": data}
        response = await self.execute(
            query=query,
            operation_name="UpdateOutstandingShares",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return UpdateOutstandingShares.model_validate(data)

    async def security(self, id: int, **kwargs: Any) -> Security:
        query = gql(
            """
            query Security($id: Int!) {
              security(id: $id) {
                name
                indicators
              }
            }
            """
        )
        variables: Dict[str, object] = {"id": id}
        response = await self.execute(
            query=query, operation_name="Security", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return Security.model_validate(data)

    async def all_security_tickers(self, **kwargs: Any) -> AllSecurityTickers:
        query = gql(
            """
            query AllSecurityTickers {
              securities {
                id
                code
                last_update
                is_delisted
                exchange {
                  code
                  virtual_exchange
                }
              }
            }
            """
        )
        variables: Dict[str, object] = {}
        response = await self.execute(
            query=query,
            operation_name="AllSecurityTickers",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return AllSecurityTickers.model_validate(data)

    async def search_security(
        self,
        search_text: str,
        limit: Union[Optional[int], UnsetType] = UNSET,
        **kwargs: Any
    ) -> SearchSecurity:
        query = gql(
            """
            query SearchSecurity($searchText: String!, $limit: Int) {
              searchSecurity(searchText: $searchText, limit: $limit) {
                id
                code
                name
                type
              }
            }
            """
        )
        variables: Dict[str, object] = {"searchText": search_text, "limit": limit}
        response = await self.execute(
            query=query, operation_name="SearchSecurity", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return SearchSecurity.model_validate(data)
