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

from dataclasses import dataclass
from datetime import datetime
from gql.gql.datetime_utils import DATETIME_FIELD
from gql.gql.graphql_client import GraphqlClient
from gql.gql.client import OperationException
from gql.gql.reporter import FailedOperationException
from functools import partial
from numbers import Number
from typing import Any, Callable, List, Mapping, Optional
from time import perf_counter
from dataclasses_json import DataClassJsonMixin

from .equipment_port_type_fragment import EquipmentPortTypeFragment, QUERY as EquipmentPortTypeFragmentQuery
from .edit_equipment_port_type_input import EditEquipmentPortTypeInput


QUERY: List[str] = EquipmentPortTypeFragmentQuery + ["""
mutation EditEquipmentPortTypeMutation($input: EditEquipmentPortTypeInput!) {
  editEquipmentPortType(input: $input) {
    ...EquipmentPortTypeFragment
  }
}

"""]

@dataclass
class EditEquipmentPortTypeMutation(DataClassJsonMixin):
    @dataclass
    class EditEquipmentPortTypeMutationData(DataClassJsonMixin):
        @dataclass
        class EquipmentPortType(EquipmentPortTypeFragment):
            pass

        editEquipmentPortType: EquipmentPortType

    data: EditEquipmentPortTypeMutationData

    @classmethod
    # fmt: off
    def execute(cls, client: GraphqlClient, input: EditEquipmentPortTypeInput) -> EditEquipmentPortTypeMutationData.EquipmentPortType:
        # fmt: off
        variables = {"input": input}
        try:
            start_time = perf_counter()
            response_text = client.call(''.join(set(QUERY)), variables=variables)
            res = cls.from_json(response_text).data
            elapsed_time = perf_counter() - start_time
            client.reporter.log_successful_operation("EditEquipmentPortTypeMutation", variables, elapsed_time)
            return res.editEquipmentPortType
        except OperationException as e:
            raise FailedOperationException(
                client.reporter,
                e.err_msg,
                e.err_id,
                "EditEquipmentPortTypeMutation",
                variables,
            )
