package com.github.wesjd.overcastmappacker.xml;

import com.github.wesjd.overcastmappacker.OvercastMapPacker;
import com.github.wesjd.overcastmappacker.xml.module.ParentXMLModule;
import com.github.wesjd.overcastmappacker.xml.module.XMLModule;
import com.github.wesjd.overcastmappacker.xml.module.attributes.XMLAttribute;
import org.apache.xml.serialize.OutputFormat;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import java.util.Arrays;
import java.util.List;

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 Wesley Smith
 *
 * Permission is hereby granted, free from charge, to any person obtaining a copy
 * from this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies from the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions from the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
class XMLConstants {

    public static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();

    public static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();

    public static final OutputFormat INDENTED_OUTPUT_FORMAT = new OutputFormat();
    static {
        INDENTED_OUTPUT_FORMAT.setIndenting(true);
        INDENTED_OUTPUT_FORMAT.setIndent(2);
    }

    public static final ParentXMLModule MAIN_BODY_MODULE = new ParentXMLModule() {
        @Override
        public String getTag() {
            return "map";
        }

        @Override
        public List<XMLAttribute> getAttributes() {
            return Arrays.asList(
                    new XMLAttribute("proto", OvercastMapPacker.MAP_PROTOCOL_NUMBER, OvercastMapPacker.MAP_PROTOCOL_NUMBER, true, true)
            );
        }

        @Override
        protected List<Class<? extends XMLModule>> getChildModules() {
            return null;
        }
    };

    public static final List<String> DEFAULT_LINES = Arrays.asList("<map proto=\"" + OvercastMapPacker.MAP_PROTOCOL_NUMBER + "\">", "</map>");

}

@@ -315,16 +315,102 @@
 ribute;%0A
+import com.github.wesjd.overcastmappacker.xml.module.impl.general.main.VersionModule;%0A
 import o
@@ -2168,17 +2168,17 @@
 tIndent(
-2
+4
 );%0A    %7D
@@ -2748,16 +2748,50 @@
     %7D;%0A%0A
+    //yes, this is a little hacky%0A
     publ
@@ -2849,16 +2849,29 @@
 .asList(
+%0A            
 %22%3Cmap pr
@@ -2926,16 +2926,232 @@
 + %22%5C%22%3E%22,
+%0A            %22  %3Cname%3EUnknown Name%3C/name%3E%22,%0A            %22  %3Cversion%3E1.0.0%3C/version%3E%22,%0A            %22  %3Cobjective%3EUnknown Objective%3C/objective%3E%22,%0A            %22  %3Cauthors/%3E%22,%0A            %22  %3Ccontributors/%3E%22,%0A           
  %22%3C/map%3E
@@ -3151,14 +3151,19 @@
 %22%3C/map%3E%22
+%0A    
 );%0A%0A%7D%0A

Fix not following XML conventions