# Generated by ariadne-codegen
# Source: queries/series-state

from typing import Any, Dict, Optional, Union

from .base_client import BaseClient
from .base_model import UNSET, UnsetType
from .series_games import SeriesGames
from .series_state import SeriesState


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


class Client(BaseClient):
    def series_games(self, series_id: str, **kwargs: Any) -> SeriesGames:
        query = gql(
            """
            query SeriesGames($seriesID: ID!) {
              seriesState(id: $seriesID) {
                id
                finished
                valid
                games {
                  id
                }
              }
            }
            """
        )
        variables: Dict[str, object] = {"seriesID": series_id}
        response = self.execute(
            query=query, operation_name="SeriesGames", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return SeriesGames.model_validate(data)

    def series_state(
        self,
        series_id: str,
        game_finished: Union[Optional[bool], UnsetType] = UNSET,
        game_started: Union[Optional[bool], UnsetType] = UNSET,
        **kwargs: Any
    ) -> SeriesState:
        query = gql(
            """
            query SeriesState($seriesID: ID!, $gameFinished: Boolean, $gameStarted: Boolean) {
              seriesState(id: $seriesID) {
                version
                id
                format
                started
                finished
                valid
                updatedAt
                startedAt
                teams {
                  __typename
                  id
                  name
                  score
                  won
                }
                games(filter: {finished: $gameFinished, started: $gameStarted}) {
                  id
                  sequenceNumber
                  type
                  started
                  finished
                  paused
                  startedAt
                  teams {
                    __typename
                    id
                    name
                    side
                    won
                    score
                    money
                    loadoutValue
                    netWorth
                    kills
                    killAssistsReceived
                    killAssistsGiven
                    teamkills
                    teamkillAssistsReceived
                    teamkillAssistsGiven
                    selfkills
                    deaths
                    firstKill
                    structuresDestroyed
                    structuresCaptured
                    killAssistsReceivedFromPlayer {
                      id
                      playerId
                      killAssistsReceived
                    }
                    objectives {
                      id
                      type
                      completedFirst
                      completionCount
                    }
                    unitKills {
                      id
                      unitName
                      count
                    }
                    players {
                      __typename
                      id
                      name
                      participationStatus
                      money
                      loadoutValue
                      netWorth
                      kills
                      killAssistsReceived
                      killAssistsGiven
                      deaths
                      firstKill
                      structuresDestroyed
                    }
                    multikills {
                      id
                      numberOfKills
                      count
                    }
                  }
                  externalLinks {
                    dataProvider {
                      name
                    }
                    externalEntity {
                      id
                    }
                  }
                  map {
                    id
                    name
                    bounds {
                      min {
                        x
                        y
                      }
                      max {
                        x
                        y
                      }
                    }
                  }
                  titleVersion {
                    name
                  }
                  clock {
                    id
                    type
                    ticking
                    ticksBackwards
                    currentSeconds
                  }
                  nonPlayerCharacters {
                    id
                    type
                    side
                    alive
                  }
                  structures {
                    id
                    type
                    side
                    teamId
                    currentHealth
                    maxHealth
                    destroyed
                  }
                  duration
                }
                title {
                  nameShortened
                }
                duration
              }
            }
            """
        )
        variables: Dict[str, object] = {
            "seriesID": series_id,
            "gameFinished": game_finished,
            "gameStarted": game_started,
        }
        response = self.execute(
            query=query, operation_name="SeriesState", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return SeriesState.model_validate(data)
