package com.gh.download;

import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.io.Serializable;
import java.util.HashMap;

@DatabaseTable(tableName = "download")
public class DownloadEntity implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	@DatabaseField(id = true, columnName="url")
	private String url;

	@DatabaseField(columnName="name")
	private String name;

	@DatabaseField(columnName="status")
	private DownloadStatus status;

	@DatabaseField(columnName="path")
	private String path;

	@DatabaseField(columnName="progress")
	private long progress;

	@DatabaseField(columnName="size")
	private long size;

	@DatabaseField(columnName="percent")
	private double percent;

	@DatabaseField(columnName="speed")
	private long speed;

	@DatabaseField(columnName="meta", dataType=DataType.SERIALIZABLE)
	private HashMap<String, String> meta;//其他

	public String getGameId() {
		if (meta != null) {
			return meta.get("gameId");
		}
		return null;
	}

	public void setGameId(String gameId) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("gameId", gameId);
	}

	public String getPackageName() {
		if (meta != null) {
			return meta.get("packageName");
		}
		return null;
	}

	public void setPackageName(String packageName) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("packageName", packageName);
	}

	public String getETag() {
		if (meta != null) {
			return meta.get("ETag");
		}
		return null;
	}

	public void setETag(String ETag) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("ETag", ETag);
	}

	public boolean isUpdate() {
		if (meta != null) {
			if ("true".equals(meta.get("isUpdate"))) {
				return true;
			}
		}
		return false;
	}

	public void setUpdate(boolean update) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("isUpdate", String.valueOf(update));
	}

	public boolean isPlugin() {
		if (meta != null) {
			if ("true".equals(meta.get("isPlugin"))) {
				return true;
			}
		}
		return false;
	}

	public void setPlugin(boolean plugin) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("isPlugin", String.valueOf(plugin));
	}

	public boolean isPluggable() {
		if (meta != null) {
			if ("true".equals(meta.get("isPluggable"))) {
				return true;
			}
		}
		return false;
	}

	public void setPluggable(boolean pluggable) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("isPluggable", String.valueOf(pluggable));
	}

	public String getPlatform() {
		if (meta != null) {
			return meta.get("platform");
		}
		return null;
	}

	public void setPlatform(String platform) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("platform", platform);
	}

	public String getIcon() {
		if (meta != null) {
			return meta.get("icon");
		}
		return null;
	}

	public void setIcon(String icon) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("icon", icon);
	}

	public String getEntrance() {
		if (meta != null) {
			return meta.get("entrance");
		}
		return null;
	}

	public void setEntrance(String entrance) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("entrance", entrance);
	}

	public String getLocation() {
		if (meta != null) {
			return meta.get("location");
		}
		return null;
	}

	public void setLocation(String location) {
		if (meta == null) {
			meta = new HashMap<>();
		}
		meta.put("location", location);
	}

	public long getSpeed() {
		return speed;
	}

	public void setSpeed(long speed) {
		this.speed = speed;
	}
	
	public HashMap<String, String> getMeta() {
		return meta;
	}

	public void setMeta(HashMap<String, String> meta) {
		if (this.meta != null) {
			this.meta.putAll(meta);
		} else {
			this.meta = meta;
		}
	}

	public double getPercent() {
		return percent;
	}

	public void setPercent(double percent) {
		this.percent = percent;
	}	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public DownloadStatus getStatus() {
		return status;
	}

	public void setStatus(DownloadStatus status) {
		this.status = status;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public long getProgress() {
		return progress;
	}

	public void setProgress(long progress) {
		this.progress = progress;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

}
