package org.batfish.job;

import org.batfish.main.ConfigurationFormat;

public final class Format {

   public static ConfigurationFormat identifyConfigurationFormat(String fileText) {
      if (fileText.contains("IOS XR")) {
         return ConfigurationFormat.CISCO_IOS_XR;
      }
      char firstChar = fileText.trim().charAt(0);
      if (firstChar == '!') {
         if (fileText.contains("set prompt")) {
            return ConfigurationFormat.VXWORKS;
         }
         else if (fileText.contains("boot system flash")) {
            return ConfigurationFormat.ARISTA;
         }
         else {
            String[] lines = fileText.split("\\n");
            for (String line : lines) {
               String trimmedLine = line.trim();
               if (trimmedLine.length() == 0 || trimmedLine.startsWith("!")) {
                  continue;
               }
               if (line.startsWith("version")) {
                  return ConfigurationFormat.CISCO;
               }
               else {
                  break;
               }
            }
         }
      }
      else if (fileText.contains("set hostname")) {
         return ConfigurationFormat.JUNIPER_SWITCH;
      }
      else if (firstChar == '#') {
         if (fileText.contains("set version")) {
            return ConfigurationFormat.FLAT_JUNIPER;
         }
         else {
            return ConfigurationFormat.JUNIPER;
         }
      }
      return ConfigurationFormat.UNKNOWN;
   }

   private Format() {
   }

}

@@ -1417,24 +1417,312 @@
   %7D%0A      %7D%0A
+      else if (fileText.contains(%22version%22) && fileText.contains(%22system%22)%0A            && fileText.contains(%22%7B%22) && fileText.contains(%22%7D%22)%0A            && fileText.contains(%22host-name%22)%0A            && fileText.contains(%22interfaces%22)) %7B%0A         return ConfigurationFormat.JUNIPER;%0A      %7D%0A
       return

update juniper hierarchical format detection