package be.jeffcheasey88.peeratcode.model;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class Puzzle {

	private int id;
	private String name;
	private String content;
	private byte[] soluce;
	private String verify;
	private int scoreMax;
	private Set<String> tags;
	private int depend;

	public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax, String tags,
			int depend) {
		this.id = id;
		this.name = name;
		this.content = content;
		this.soluce = soluce;
		this.verify = verify;
		this.scoreMax = scoreMax;
		setTags(tags);
		this.depend = depend;
	}

	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getContent() {
		return content;
	}

	public byte[] getSoluce() {
		return this.soluce;
	}

	public int getScoreMax() {
		return this.scoreMax;
	}

	public Set<String> getTags() {
		return this.tags;
	}

	/**
	 * DO NOT EVER EVER SHOW TO MISTER LUDWIG XD
	 * 
	 * @return DEATH
	 */
	public JSONArray getJsonTags() {
		if (tags == null)
			return null;
		JSONArray tagsJSON = new JSONArray();
		for (String tag : tags) {
			JSONObject tagJSON = new JSONObject();
			tagJSON.put("name", tag);
			tagsJSON.add(tagJSON);
		}
		return tagsJSON;
	}

	public void setTags(String tags) {
		if (tags == null || tags.isEmpty())
			this.tags = null;
		else
			this.tags = new HashSet<String>(Arrays.asList(tags.split(",")));
	}

	public int getDepend() {
		return this.depend;
	}

	@Override
	public boolean equals(Object object) {
		if (this == object)
			return true;
		if (!(object instanceof Puzzle))
			return false;
		return this.id == (((Puzzle) object).id);
	}

	@Override
	public int hashCode() {
		return id;
	}
}
