package org.apache.logging.log4j.core.config.json;

import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Order;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.util.Loader;

@Plugin(
   name = "JsonConfigurationFactory",
   category = "ConfigurationFactory"
)
@Order(6)
public class JsonConfigurationFactory extends ConfigurationFactory {
   private static final String[] SUFFIXES = new String[]{".json", ".jsn"};
   private static final String[] dependencies = new String[]{"com.fasterxml.jackson.databind.ObjectMapper", "com.fasterxml.jackson.databind.JsonNode", "com.fasterxml.jackson.core.JsonParser"};
   private final boolean isActive;

   public JsonConfigurationFactory() {
      String[] arr$ = dependencies;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         String dependency = arr$[i$];
         if (!Loader.isClassAvailable(dependency)) {
            LOGGER.debug("Missing dependencies for Json support");
            this.isActive = false;
            return;
         }
      }

      this.isActive = true;
   }

   protected boolean isActive() {
      return this.isActive;
   }

   public Configuration getConfiguration(ConfigurationSource source) {
      return !this.isActive ? null : new JsonConfiguration(source);
   }

   public String[] getSupportedTypes() {
      return SUFFIXES;
   }
}
