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

import com.google.gson.annotations.Expose;
import com.persagy.adm.diagram.core.DiagramBuilder;
import com.persagy.adm.diagram.core.line.LineLayoutManager;
import com.persagy.adm.diagram.core.model.base.XY;

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

/**
 * 节点之间的连线
 * @author zhaoyk
 */
public class Line extends AbstractLine {

	@Expose
	private int direction; //连线的方向(1：from->to, 0:无方向, -1:to->from)

	/**
	 * 起点
	 */
	@Expose
	private ConnectPoint from;

	/**
	 * 终点
	 */
	@Expose
	private ConnectPoint to;

	/**
	 * 途经点列表，依次记录相对前一点的偏移量
	 */
	@Expose
	private List<XY> passingPoints;

	/**
	 * 关系数据的类型, graphCode/relCode
	 */
	@Expose
	private String relType;

	/**
	 * 途径的干管，标注连线中与干管重合的线段部分
	 */
	@Expose
	private List<PassingMainPipe> passingMainPipes;

	/**
	 * 连线的坐标点序列(包含from,to连接点坐标)
	 */
	private List<XY> locationPath;

	@Override
	public void layout(Object layoutContext) {
		LineLayoutManager layoutManager = (LineLayoutManager) layoutContext;
		layoutManager.layout(this);

		//test code TODO
		locationPath = new ArrayList<>();
		if(from.getLocation() != null && to.getLocation() != null) {
			locationPath.add(from.getLocation());
			locationPath.add(to.getLocation());
		}
	}

	public int getDirection() {
		return direction;
	}

	public void setDirection(int direction) {
		this.direction = direction;
	}

	public ConnectPoint getFrom() {
		return from;
	}

	public void setFrom(ConnectPoint from) {
		this.from = from;
	}

	public ConnectPoint getTo() {
		return to;
	}

	public void setTo(ConnectPoint to) {
		this.to = to;
	}

	public List<XY> getPassingPoints() {
		return passingPoints;
	}

	public void setPassingPoints(List<XY> passingPoints) {
		this.passingPoints = passingPoints;
	}

	public String getRelType() {
		return relType;
	}

	public void setRelType(String relType) {
		this.relType = relType;
	}

	public List<PassingMainPipe> getPassingMainPipes() {
		return passingMainPipes;
	}

	public void setPassingMainPipes(List<PassingMainPipe> passingMainPipes) {
		this.passingMainPipes = passingMainPipes;
	}

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

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

	public static class PassingMainPipe {

		/**
		 * 途径的干管id
		 */
		private String mainPipeId;

		/**
		 * 途径干管部分的起点序号(在连线点中的位置，from点序号为0)
		 */
		private int point1Index;

		/**
		 * 途径干管部分的终点序号(在连线点中的位置，from点序号为0)
		 */
		private int point2Index;

		public String getMainPipeId() {
			return mainPipeId;
		}

		public void setMainPipeId(String mainPipeId) {
			this.mainPipeId = mainPipeId;
		}

		public int getPoint1Index() {
			return point1Index;
		}

		public void setPoint1Index(int point1Index) {
			this.point1Index = point1Index;
		}

		public int getPoint2Index() {
			return point2Index;
		}

		public void setPoint2Index(int point2Index) {
			this.point2Index = point2Index;
		}

	}

}
