#!/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 gql_client.runtime.enum_utils import enum_field_metadata
from ..enum.service_status import ServiceStatus

from ..input.service_filter_input import ServiceFilterInput


# fmt: off
QUERY: List[str] = ["""
query Services($after: Cursor, $before: Cursor, $filterBy: [ServiceFilterInput!], $first: Int, $last: Int) {
  services(after: $after, before: $before, filterBy: $filterBy, first: $first, last: $last) {
    edges {
      node {
        id
        name
        status
        customer {
          name
          id
        }
        serviceType {
          id
          name
        }
        properties {
          id
          stringValue
          rawValue
          rangeToValue
          rangeFromValue

          longitudeValue
          latitudeValue
          intValue
          floatValue
          booleanValue
        }
      }
      cursor
    }
    pageInfo {
      endCursor
      hasNextPage
      hasPreviousPage
      startCursor
    }

  }
}
"""
]


class Services:
    @dataclass(frozen=True)
    class ServicesData(DataClassJsonMixin):
        @dataclass(frozen=True)
        class ServiceConnection(DataClassJsonMixin):
            @dataclass(frozen=True)
            class ServiceEdge(DataClassJsonMixin):
                @dataclass(frozen=True)
                class Service(DataClassJsonMixin):
                    @dataclass(frozen=True)
                    class Customer(DataClassJsonMixin):
                        name: str
                        id: str

                    @dataclass(frozen=True)
                    class ServiceType(DataClassJsonMixin):
                        id: str
                        name: str

                    @dataclass(frozen=True)
                    class Property(DataClassJsonMixin):
                        id: str
                        stringValue: Optional[str]
                        rawValue: Optional[str]
                        rangeToValue: Optional[Number]
                        rangeFromValue: Optional[Number]
                        longitudeValue: Optional[Number]
                        latitudeValue: Optional[Number]
                        intValue: Optional[int]
                        floatValue: Optional[Number]
                        booleanValue: Optional[bool]

                    id: str
                    name: str
                    status: ServiceStatus = _field(metadata=enum_field_metadata(ServiceStatus))
                    customer: Optional[Customer]
                    serviceType: ServiceType
                    properties: List[Property]

                node: Optional[Service]
                cursor: str

            @dataclass(frozen=True)
            class PageInfo(DataClassJsonMixin):
                endCursor: Optional[str]
                hasNextPage: bool
                hasPreviousPage: bool
                startCursor: Optional[str]

            edges: List[ServiceEdge]
            pageInfo: PageInfo

        services: ServiceConnection

    # fmt: off
    @classmethod
    def execute(cls, client: Client, after: Optional[str] = None, before: Optional[str] = None, filterBy: List[ServiceFilterInput] = [], first: Optional[int] = None, last: Optional[int] = None) -> ServicesData.ServiceConnection:
        variables: Dict[str, Any] = {"after": after, "before": before, "filterBy": filterBy, "first": first, "last": last}
        new_variables = encode_variables(variables, custom_scalars)
        response_text = client.execute(
            gql("".join(set(QUERY))), variable_values=new_variables
        )
        res = cls.ServicesData.from_dict(response_text)
        return res.services

    # fmt: off
    @classmethod
    async def execute_async(cls, client: Client, after: Optional[str] = None, before: Optional[str] = None, filterBy: List[ServiceFilterInput] = [], first: Optional[int] = None, last: Optional[int] = None) -> ServicesData.ServiceConnection:
        variables: Dict[str, Any] = {"after": after, "before": before, "filterBy": filterBy, "first": first, "last": last}
        new_variables = encode_variables(variables, custom_scalars)
        response_text = await client.execute_async(
            gql("".join(set(QUERY))), variable_values=new_variables
        )
        res = cls.ServicesData.from_dict(response_text)
        return res.services
