package org.mcupdater.instance;

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

public class Instance {
	private String mcversion;
	private String revision;
	private String hash = "";
	private List<FileInfo> instanceFiles = new ArrayList<>();
	private List<FileInfo> jarMods = new ArrayList<>();
	private Map<String, Boolean> optionalMods = new HashMap<>();
	
	public List<FileInfo> getInstanceFiles() {
		return instanceFiles;
	}
	
	public void setInstanceFiles(List<FileInfo> instanceFiles) {
		this.instanceFiles = instanceFiles;
	}
	
	public Map<String, Boolean> getOptionalMods() {
		return this.optionalMods;
	}
	
	public Boolean getModStatus(String key) {
		return this.optionalMods.get(key);
	}
	
	public void setModStatus(String key, Boolean value) {
		this.optionalMods.put(key, value);
	}
	
	public String getMCVersion() {
		return mcversion;
	}
	
	public void setMCVersion(String mcversion) {
		this.mcversion = mcversion;
	}
	
	public String getRevision() {
		return revision;
	}
	
	public void setRevision(String revision) {
		this.revision = revision;
	}
	
	public List<FileInfo> getJarMods() {
		return jarMods;
	}
	
	public void setJarMods(List<FileInfo> jarMods) {
		this.jarMods = jarMods;
	}
	
	public FileInfo findJarMod(String id) {
		for (FileInfo entry : this.jarMods) {
			if (entry.getModId().equals(id)) {
				return entry;
			}
		}
		return null;
	}

	public void addJarMod(String id, String md5) {
		FileInfo entry = new FileInfo();
		entry.setModId(id);
		entry.setMD5(md5);
		this.jarMods.add(entry);
	}
	
	public void addMod(String id, String md5, String filename) {
		FileInfo entry = new FileInfo();
		entry.setModId(id);
		entry.setMD5(md5);
		entry.setFilename(filename);
		this.instanceFiles.add(entry);
	}

	public String getHash() {
		return hash;
	}

	public void setHash(String hash) {
		this.hash = hash;
	}
}

@@ -656,33 +656,137 @@
 ptionalMods;%0A%09%7D%0A
-%09
+%0A%09public void setOptionalMods(Map%3CString,Boolean%3E optionalMods) %7B%0A%09%09this.optionalMods = optionalMods;%0A%09%7D%0A
 %0A%09public Boolean
@@ -2000,10 +2000,961 @@
 ash;%0A%09%7D%0A
+%0A%09@Override%0A%09public String toString() %7B%0A%09%09StringBuilder serializer = new StringBuilder();%0A%09%09serializer.append(%22%7B%22);%0A%09%09serializer.append(%22mcversion:%22).append(this.mcversion).append(%22;%22);%0A%09%09serializer.append(%22revision:%22).append(this.revision).append(%22;%22);%0A%09%09serializer.append(%22hash:%22).append(this.hash).append(%22;%22);%0A%09%09serializer.append(%22instanceFiles:%5B%22);%0A%09%09for (FileInfo entry : instanceFiles) %7B%0A%09%09%09serializer.append(entry.toString()).append(%22;%22);%0A%09%09%7D%0A%09%09serializer.append(%22%5D;%22);%0A%09%09serializer.append(%22jarMods:%5B%22);%0A%09%09for (FileInfo entry : jarMods) %7B%0A%09%09%09serializer.append(entry.toString()).append(%22;%22);%0A%09%09%7D%0A%09%09serializer.append(%22%5D;%22);%0A%09%09serializer.append(%22optionalMods:%5B%22);%0A%09%09for (Map.Entry%3CString,Boolean%3E entry : optionalMods.entrySet()) %7B%0A%09%09%09serializer.append(%22%7Bkey:%22).append(entry.getKey()).append(%22;value:%22).append(entry.getValue().toString()).append(%22%7D;%22);%0A%09%09%7D%0A%09%09serializer.append(%22%5D;%22);%0A%09%09serializer.append(%22%7D%22);%0A%09%09return serializer.toString();%0A%09%7D%0A%0A
 %7D%0A

Fix saved optional mod selections being applied when instance data is loaded.