
package com.limewoodMedia.nsapi.holders;

import com.limewoodMedia.nsapi.enums.IArguments;
import com.limewoodMedia.nsapi.enums.IShards;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.plaf.synth.Region;

/**
 * A data object for region data
 * @author Joakim Lindskog
 *
 */
public class RegionData {
    public static final String ROOT_TAG = "region";

    /**
	 * Shards for region data
	 * @author Joakim Lindskog
	 *
	 */
	public enum Shards implements IShards {
		NAME("name"),
		FLAG("flag"),
		DELEGATE("delegate"),
		FOUNDER("founder"),
		FACTBOOK("factbook"),
		HAPPENINGS("happenings"),
		MESSAGES("messages"),
		NUM_NATIONS("numnations"),
		NATIONS("nations"),
		DELEGATE_VOTES("delegatevotes"),
		DELEGATE_AUTH("delegateauth"),
        FOUNDER_AUTH("founderauth"),
		GA_VOTES("gavote"),
		SC_VOTES("scvote"),
		POWER("power"),
		EMBASSIES("embassies"),
		TAGS("tags"),
		OFFICERS("officers");

		private String name;
		private String tag;
		private Map<IArguments, String> arguments;

		Shards(String name, String tag) {
			this.name = name;
			this.tag = tag;
		}

		Shards(String nameTag) {
			this(nameTag, nameTag);
		}

		public String getName() {
			return this.name;
		}

		public String getTag() {
			return this.tag;
		}
		
		public Map<IArguments, String> getArguments() {
			if(arguments != null) {
				return new HashMap<IArguments, String>(arguments);
			}
			return arguments;
		}
		
		public Shards setArgument(Arguments name, String value) {
			if(arguments == null) {
				arguments = new HashMap<IArguments, String>();
			}
			arguments.put(name, value);
			return this;
		}

		public enum SubTags {
			HAPPENINGS_EVENT("event"),
			MESSAGES_POST("post"),
			MESSAGES_POST_TIMESTAMP("timestamp"),
			MESSAGES_POST_NATION("nation"),
			MESSAGES_POST_EMBASSY("embassy"),
			MESSAGES_POST_MESSAGE("message"),
			WA_VOTES_FOR("for"),
			WA_VOTES_AGAINST("against"),
			EMBASSIES_EMBASSY("embassy"),
			TAGS_TAG("tag"),
			OFFICERS_OFFICER("officer"),
			OFFICER_NATION("nation"),
			OFFICER_OFFICE("office"),
			OFFICER_AUTHORITY("authority"),
			OFFICER_TIME("time"),
			OFFICER_BY("by"),
			OFFICER_ORDER("order");

			private String tag;

			SubTags(String tag) {
				this.tag = tag;
			}

			public String getTag() {
				return this.tag;
			}
		}
		
		public enum Arguments implements IArguments {
			MESSAGES_OFFSET("offset");
			
			private String name;

			Arguments(String name) {
				this.name = name;
			}

			public String getName() {
				return this.name;
			}
		}

        public enum Attributes {
            RMB_POST_ID("id");

            private String name;

            Attributes(String name) {
                this.name = name;
            }

            public String getName() {
                return this.name;
            }
        }
	}
	
	public String name;
	public String flagURL;
	public String delegate;
	public String founder;
	public String factbook;
	public List<RegionHappening> happenings;
	public List<RMBMessage> messages;
	public int numNations;
	public String[] nations;
	public int delegateVotes;
    public List<Officer.Authority> delegateAuth;
    public List<Officer.Authority> founderAuth;
	public WAVotes generalAssemblyVotes;
	public WAVotes securityCouncilVotes;
	public String power;
	public List<Embassy> embassies;
	public List<String> tags;
	public List<Officer> officers;

	public RegionData() {
        delegateAuth = new ArrayList<>();
        founderAuth = new ArrayList<>();
		officers = new ArrayList<>();
	}
	
	@Override
	public String toString() {
		String str = "Region"
				+"\n\tname:\t"+name
				+"\n\tflagURL:\t"+flagURL
				+"\n\tdelegate:\t"+delegate
				+"\n\tfounder:\t"+founder
				+"\n\tfactbook:\t"+factbook
				+"\n\thappenings:";
		if(happenings != null) {
			for(Happening h : happenings) {
				str += "\n" + h;
			}
		}
		str += "\n\tmessages:";
		if(messages != null) {
			for(RMBMessage msg : messages) {
				str += "\n" + msg;
			}
		}
		str += "\n\tnumNations:\t"+numNations
				+"\n\tnations:";
		if(nations != null) {
			for(String n : nations) {
				str += "\n\t\t" + n;
			}
		}
		str += "\n\tdelegateVotes:\t"+delegateVotes
				+"\n\tgeneralAssemblyVotes:\t"+generalAssemblyVotes
				+"\n\tsecurityCouncilVotes:\t"+securityCouncilVotes
				+"\n\tpower:\t"+power
				+"\n\tembassies:";
		if(embassies != null) {
			for(Embassy e : embassies) {
				str += "\n" + e;
			}
		}
		str += "\n\ttags:";
		if(tags != null) {
			for(String tag : tags) {
				str += "\n\t\t" + tag;
			}
		}
		return str;
	}
}