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

import com.google.gson.annotations.Expose;
import com.persagy.adm.diagram.core.model.Const;
import com.persagy.adm.diagram.core.model.base.XY;

import java.util.List;

/**
 * 连接锚点
 * @author zhaoyk
 */
public class Anchor {

	public static final String TYPE_NON = Const.NON;

	public static final String TYPE_IN = "in";

	public static final String TYPE_OUT = "out";

	@Expose
	private String code; //锚点位置代码，TL|T1等，系统自动生成

	@Expose
	private String name; //锚点名称

	@Expose
	private String type; //进出

	@Expose
	private List<String> acceptRelations; //支持的关系类型(连线)，格式: graphCode/relCode

	@Expose
	private List<String> toEquipmentTypes; //连线另一端的设备类型

	@Expose
	private boolean attachToOutline = true; //是否自动吸附到所在方向的边框上

	@Expose
	private boolean multiple; //是否支持动态多锚点，编辑时可指定数量，按默认规则(平分所在边线)进行定位

	@Expose
	private String shape; //TODO 锚点的绘制策略，待细化


	private float xOffset; //布局处理后的水平偏移量

	private float yOffset; //布局处理后的垂直偏移量


	public Anchor() {

	}

	public Anchor(String code) {
		this.code = code;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

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

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<String> getAcceptRelations() {
		return acceptRelations;
	}

	public void setAcceptRelations(List<String> acceptRelations) {
		this.acceptRelations = acceptRelations;
	}

	public List<String> getToEquipmentTypes() {
		return toEquipmentTypes;
	}

	public void setToEquipmentTypes(List<String> toEquipmentTypes) {
		this.toEquipmentTypes = toEquipmentTypes;
	}

	public boolean isAttachToOutline() {
		return attachToOutline;
	}

	public void setAttachToOutline(boolean attachToOutline) {
		this.attachToOutline = attachToOutline;
	}

	public boolean isMultiple() {
		return multiple;
	}

	public void setMultiple(boolean multiple) {
		this.multiple = multiple;
	}

	public String getShape() {
		return shape;
	}

	public void setShape(String shape) {
		this.shape = shape;
	}

	public XY calcLocation(XY legendSize) {
		XY legendLocation = new XY(0, 0);
		char c1 = code.charAt(0);
		char c2 = code.charAt(1);
		int idx = (int)c2 - 48;
		int part = 6;
		switch (c1){
			case 'T':
				if(c2 == 'L')
					return new XY(legendLocation);
				if(c2 == 'R')
					return new XY(legendLocation.x + legendSize.x, legendLocation.y);
				return new XY(legendLocation.x + legendSize.x / part * idx, legendLocation.y);
			case 'B':
				if(c2 == 'L')
					return new XY(legendLocation.x, legendLocation.y + legendSize.y);
				if(c2 == 'R')
					return new XY(legendLocation.x + legendSize.x, legendLocation.y + legendSize.y);
				return new XY(legendLocation.x + legendSize.x / part * idx, legendLocation.y + legendSize.y);
			case 'L':
				return new XY(legendLocation.x, legendLocation.y + legendSize.y / part * idx);
			case 'R':
				return new XY(legendLocation.x + legendSize.x, legendLocation.y + legendSize.y / part * idx);
		}
		return null;
	}

}
