package com.tsi.navi.vo;

import com.naver.maps.geometry.LatLng;
import com.naver.maps.map.overlay.Marker;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Builder
public class NodeVo {
    private long    nodeId;
    private String  name;
    //private double  lat;
    //private double  lng;
    private int     type;
    private boolean isReal;
    private boolean online;

    public Marker marker;
    public LatLng latLng;
    public HashMap<Integer, NodeVo> toNodeMap;      // 방향코드, 노드정보
    public HashMap<Integer, NodeVo> fromNodeMap;    // 방향코드, 노드정보
    public Set<Integer> inDirMap;
    public Set<Integer> runDirMap;

    public Long getId() {
        return Long.valueOf(this.nodeId);
    }

    public String getDirCode() {
        if (this.inDirMap == null) {
            return "[]";
        }
        String dirCode = "";
        Iterator<Integer> iter = this.inDirMap.iterator();
        while(iter.hasNext()){
            if (dirCode.isEmpty()) {
                dirCode = "[" + String.valueOf(iter.next());
            }
            else {
                dirCode = dirCode + "," + String.valueOf(iter.next());
            }
        }
        return dirCode + "]";
    }

    public boolean containsFromNode(long nodeId) {
        for (Map.Entry<Integer, NodeVo> obj : this.fromNodeMap.entrySet()) {
            if (obj.getValue().getNodeId() == nodeId) {
                return true;
            }
        }
        return false;
    }
    public boolean containsToNode(long nodeId) {
        for (Map.Entry<Integer, NodeVo> obj : this.toNodeMap.entrySet()) {
            if (obj.getValue().getNodeId() == nodeId) {
                return true;
            }
        }
        return false;
    }
}
