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

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 = "YamlConfigurationFactory",
   category = "ConfigurationFactory"
)
@Order(7)
public class YamlConfigurationFactory extends ConfigurationFactory {
   private static final String[] SUFFIXES = new String[]{".yml", ".yaml"};
   private static final String[] dependencies = new String[]{"com.fasterxml.jackson.databind.ObjectMapper", "com.fasterxml.jackson.databind.JsonNode", "com.fasterxml.jackson.core.JsonParser", "com.fasterxml.jackson.dataformat.yaml.YAMLFactory"};
   private final boolean isActive;

   public YamlConfigurationFactory() {
      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 Yaml support");
            this.isActive = false;
            return;
         }
      }

      this.isActive = true;
   }

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

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

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