#!/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.resource_relationship_types_kind import ResourceRelationshipTypesKind

from ..input.add_resource_relationship_input import AddResourceRelationshipInput


# fmt: off
QUERY: List[str] = ["""
mutation addResourceRelationship($input: AddResourceRelationshipInput!) {
  addResourceRelationship(input: $input) {
    id
     resourceRelationshipTypes
    resourceA{
      id
      name
    }
    resourceB{
      id
      name
    }
    location{
      id
      name
    }
  }
}
"""
]


class addResourceRelationship:
    @dataclass(frozen=True)
    class addResourceRelationshipData(DataClassJsonMixin):
        @dataclass(frozen=True)
        class ResourceRelationship(DataClassJsonMixin):
            @dataclass(frozen=True)
            class Resource(DataClassJsonMixin):
                id: str
                name: str

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

            id: str
            resourceRelationshipTypes: ResourceRelationshipTypesKind = _field(metadata=enum_field_metadata(ResourceRelationshipTypesKind))
            resourceA: Resource
            resourceB: Optional[Resource]
            location: Optional[Location]

        addResourceRelationship: ResourceRelationship

    # fmt: off
    @classmethod
    def execute(cls, client: Client, input: AddResourceRelationshipInput) -> addResourceRelationshipData.ResourceRelationship:
        variables: Dict[str, Any] = {"input": input}
        new_variables = encode_variables(variables, custom_scalars)
        response_text = client.execute(
            gql("".join(set(QUERY))), variable_values=new_variables
        )
        res = cls.addResourceRelationshipData.from_dict(response_text)
        return res.addResourceRelationship

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