#!/usr/bin/env python3
# @generated AUTOGENERATED file. Do not Change!

from dataclasses import dataclass, field as _field
from ...config import custom_scalars, datetime
from gql_client.runtime.variables import encode_variables
from gql import gql, Client
from gql.transport.exceptions import TransportQueryError
from functools import partial
from numbers import Number
from typing import Any, AsyncGenerator, Dict, List, Generator, Optional
from time import perf_counter
from dataclasses_json import DataClassJsonMixin, config

from ..fragment.customer import CustomerFragment, QUERY as CustomerFragmentQuery


# fmt: off
QUERY: List[str] = CustomerFragmentQuery + ["""
query ServiceTypeServicesQuery($id: ID!) {
  serviceType: node(id: $id) {
    ... on ServiceType {
      services {
        id
        name
        externalId
        customer {
          ...CustomerFragment
        }
      }
    }
  }
}

"""
]


class ServiceTypeServicesQuery:
    @dataclass(frozen=True)
    class ServiceTypeServicesQueryData(DataClassJsonMixin):
        @dataclass(frozen=True)
        class Node(DataClassJsonMixin):
            @dataclass(frozen=True)
            class Service(DataClassJsonMixin):
                @dataclass(frozen=True)
                class Customer(CustomerFragment):
                    pass

                id: str
                name: str
                externalId: Optional[str]
                customer: Optional[Customer]

            services: List[Service]

        serviceType: Optional[Node]

    # fmt: off
    @classmethod
    def execute(cls, client: Client, id: str) -> Optional[ServiceTypeServicesQueryData.Node]:
        variables: Dict[str, Any] = {"id": id}
        new_variables = encode_variables(variables, custom_scalars)
        response_text = client.execute(
            gql("".join(set(QUERY))), variable_values=new_variables
        )
        res = cls.ServiceTypeServicesQueryData.from_dict(response_text)
        return res.serviceType

    # fmt: off
    @classmethod
    async def execute_async(cls, client: Client, id: str) -> Optional[ServiceTypeServicesQueryData.Node]:
        variables: Dict[str, Any] = {"id": id}
        new_variables = encode_variables(variables, custom_scalars)
        response_text = await client.execute_async(
            gql("".join(set(QUERY))), variable_values=new_variables
        )
        res = cls.ServiceTypeServicesQueryData.from_dict(response_text)
        return res.serviceType
