package com.l7tech.gateway.pm2.graphql.service;

import com.l7tech.gateway.pm2.graphql.beans.PM2GraphQLRequest;
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import io.leangen.graphql.GraphQLSchemaGenerator;
import java.util.Collections;
import java.util.Map;
import org.springframework.context.ApplicationContext;

public class PM2GraphQLService {
   private static PM2GraphQLService a = null;
   private final GraphQL b;

   public static synchronized PM2GraphQLService getInstance(ApplicationContext var0) {
      if (a == null) {
         a = new PM2GraphQLService(var0);
      }

      return a;
   }

   private PM2GraphQLService(ApplicationContext var1) {
      GraphQLSchemaGenerator var2 = new GraphQLSchemaGenerator()
         .withOperationsFromSingletons(
            new Object[]{new PM2CoreService(var1), new PM2CoreAssertionsService(var1), new PM2ResourcesService(var1), new PM2SecretsService(var1)}
         );
      this.b = GraphQL.newGraphQL(var2.generate()).build();
   }

   public Map<String, Object> executeGraphQL(PM2GraphQLRequest var1) {
      ExecutionInput var2 = ExecutionInput.newExecutionInput()
         .query(var1.getQuery())
         .variables(var1.getVariables() == null ? Collections.emptyMap() : var1.getVariables())
         .build();
      ExecutionResult var3 = this.b.execute(var2);
      return var3.toSpecification();
   }
}
