package com.its.bis.service;

import com.its.bis.dto.BisObe;
import com.its.bis.dto.TbLinkDto;
import com.its.bis.dto.TbNodeDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Slf4j
@Service
@RequiredArgsConstructor
public class AppRepositoryService {

    private final ConcurrentHashMap<Long, TbNodeDto> nodeMap = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<Long, TbLinkDto> linkMap = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<String, TbLinkDto> sectMap = new ConcurrentHashMap<>();

    private final ConcurrentHashMap<String, BisObe> obeMap = new ConcurrentHashMap<>();

    public Set<Map.Entry<Long, TbNodeDto>> getEntrySetNode() {
        return this.nodeMap.entrySet();
    }
    public ConcurrentMap<Long, TbNodeDto> getNodeMap() {
        return this.nodeMap;
    }

    public TbNodeDto putNodeMap(TbNodeDto obj) {
        return this.nodeMap.put(obj.getNodeId(), obj);
    }
//    public TbNodeDto getNodeMap(Long nodeId) {
//        return this.nodeMap.get(nodeId);
//    }

    public TbLinkDto putLinkMap(TbLinkDto obj) {
        return this.linkMap.put(obj.getLinkId(), obj);
    }
    public TbLinkDto putSectMap(TbLinkDto obj) {
        return this.sectMap.put(obj.getFNodeId() + ":" + obj.getTNodeId(), obj);
    }
    public TbLinkDto getSectMap(Long fNodeId, Long tNodeId) {
        return this.sectMap.get(fNodeId + ":" + tNodeId);
    }

    public BisObe putObeMap(BisObe obj) {
        return this.obeMap.put(obj.getDeviceId(), obj);
    }
    public BisObe getObeMap(String deviceId) {
        return this.obeMap.get(deviceId);
    }

}
