package com.persagy.adm.diagram.core.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.annotations.Expose;
import com.persagy.adm.diagram.core.model.base.XY;
import com.persagy.adm.diagram.core.model.legend.Anchor;
import com.persagy.adm.diagram.core.model.legend.Legend;

import java.util.HashMap;
import java.util.Map;

/**
 * 设备节点
 * @author zhaoyk
 */
public class EquipmentNode extends DiagramNode {

	public static final String TYPE = "equipmentNode";

	/**
	 * 绑定的数据对象id
	 */
	@Expose
	private String objId;

	/**
	 * 数据对象的classCode
	 */
	@Expose
	private String objClassCode;

	@Expose
	private String legendId;

	@Expose
	private Label label;

	@JsonIgnore
	private Legend legend;

	/**
	 * 图例中锚点的位置坐标(相对于图例的位置)
	 */
	private Map<String, XY> anchorLocations;

	public EquipmentNode() {
		this.compType = TYPE;
	}

	@Override
	public void layout() {
		setSize(new XY(legend.getWidth(), legend.getHeight()));
		if(legend.getAnchors() != null) {
			anchorLocations = new HashMap<>();
			for(Anchor anchor : legend.getAnchors()) {
				anchorLocations.put(anchor.getCode(), anchor.calcLocation(size));
			}
		}

		if(label != null) {
			label.setLocation(new XY(10, 10)); //TODO
		}

		//TODO anchors
	}

	public String getObjId() {
		return objId;
	}

	public void setObjId(String objId) {
		this.objId = objId;
	}

	public String getObjClassCode() {
		return objClassCode;
	}

	public void setObjClassCode(String objClassCode) {
		this.objClassCode = objClassCode;
	}

	public String getObjSystemCode(){
		return objClassCode.substring(0, 4);
	}

	public Label getLabel() {
		return label;
	}

	public void setLabel(Label label) {
		this.label = label;
	}

	public String getLegendId() {
		return legendId;
	}

	public void setLegendId(String legendId) {
		this.legendId = legendId;
	}

	public void setLegend(Legend legend) {
		this.legend = legend;
	}

	public Legend getLegend() {
		return legend;
	}

	public Map<String, XY> getAnchorLocations() {
		return anchorLocations;
	}

}
