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

import com.google.gson.annotations.Expose;
import com.persagy.adm.diagram.core.model.base.Container;
import com.persagy.adm.diagram.core.model.AbstractLine;
import com.persagy.adm.diagram.core.model.base.IEquipHolder;
import com.persagy.adm.diagram.core.model.base.XY;
import com.persagy.adm.diagram.core.model.logic.DataFilter;

import java.util.ArrayList;
import java.util.List;

/**
 * 干管/线
 * @author zhaoyk
 */
public class MainPipe extends AbstractLine implements IEquipHolder {

	public static final String TYPE = "mainPipe";

	@Expose
	private String remark;

	@Expose
	private String pipeType;

	@Expose
	private List<String> passbyRels; //要经过干管的关系类型，格式: graphCode/relCode

	@Expose
	private List<String> connectEquips; //可以直连干管的设备类型

	@Expose
	private List<String> equipmentTypes; //可以放置在干管上的设备类型；或是绑定的设备类型

	@Expose
	private boolean bindEquipment; //干管是否绑定具体设备

	/**
	 * 设备数据过滤器
	 */
	@Expose
	private DataFilter dataFilter;

	@Expose
	private List<List<MainPipePoint>> path = new ArrayList<>();

	/**
	 * 连线的坐标点序列，多条线
	 */
	private List<List<XY>> locationPath;

	@Override
	public String getId() {
		return id;
	}

	@Override
	public void setId(String id) {
		this.id = id;
	}

	@Override
	public String getName() {
		return name;
	}

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

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getPipeType() {
		return pipeType;
	}

	public void setPipeType(String pipeType) {
		this.pipeType = pipeType;
	}

	public List<String> getPassbyRels() {
		return passbyRels;
	}

	public void setPassbyRels(List<String> passbyRels) {
		this.passbyRels = passbyRels;
	}

	public List<String> getConnectEquips() {
		return connectEquips;
	}

	public void setConnectEquips(List<String> connectEquips) {
		this.connectEquips = connectEquips;
	}

	@Override
	public List<String> getEquipmentTypes() {
		return equipmentTypes;
	}

	public void setEquipmentTypes(List<String> equipmentTypes) {
		this.equipmentTypes = equipmentTypes;
	}

	public boolean isBindEquipment() {
		return bindEquipment;
	}

	public void setBindEquipment(boolean bindEquipment) {
		this.bindEquipment = bindEquipment;
	}

	@Override
	public DataFilter getDataFilter() {
		return dataFilter;
	}

	public void setDataFilter(DataFilter dataFilter) {
		this.dataFilter = dataFilter;
	}

	public List<List<MainPipePoint>> getPath() {
		return path;
	}

	public void setPath(List<List<MainPipePoint>> path) {
		this.path = path;
	}

	public List<List<XY>> getLocationPath() {
		return locationPath;
	}

	public void setLocationPath(List<List<XY>> locationPath) {
		this.locationPath = locationPath;
	}

	@Override
	public void layout(Object layoutContext) {
		DiagramTemplate template = (DiagramTemplate)layoutContext;
		locationPath = new ArrayList<>(path.size());
		for (List<MainPipePoint> line : path) {
			ArrayList<XY> list = new ArrayList<>();
			locationPath.add(list);

			for(MainPipePoint p : line) {
				Container container = template.getContainerById(p.getContainerId());
				if(container != null && !container.isAbsolutePosition()) {
					ContainerRefPoint rp = ContainerRefPoint.getRefPoint(container, p.getRefPointName(), container.locationToRoot());
					list.add(new XY(rp.getLocation().x + p.getOffset().x , rp.getLocation().y + p.getOffset().y));
				}
			}
		}
	}

}
