package com.its.vds.service;

import com.its.vds.dto.TbVdsCtlrDto;
import io.netty.channel.Channel;
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, TbVdsCtlrDto> ctlrMap = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<String, TbVdsCtlrDto> ipAddrMap = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<Channel, TbVdsCtlrDto> channelMap = new ConcurrentHashMap<>();

    public void initCtlrInfo() {
        try {
            for (Map.Entry<Long, TbVdsCtlrDto> e : this.ctlrMap.entrySet()) {
                TbVdsCtlrDto obj = e.getValue();
                obj.setDelYn("Y");
            }
        }
        catch (Exception e) {
            log.error("AppRepositoryService.initCtlrInfo: Exception: {}.", e.toString());
        }
    }
    public Set<Map.Entry<Long, TbVdsCtlrDto>> getEntrySetCtrl() {
        return this.ctlrMap.entrySet();
    }
    public ConcurrentMap<Long, TbVdsCtlrDto> getCtlrMap() {
        return this.ctlrMap;
    }
    public ConcurrentMap<String, TbVdsCtlrDto> getIpAddrMap() {
        return this.ipAddrMap;
    }
    public ConcurrentMap<Channel, TbVdsCtlrDto> getChannelMap() {
        return this.channelMap;
    }

    public TbVdsCtlrDto putCtlrMap(TbVdsCtlrDto obj) {
        return this.ctlrMap.put(obj.getVdsCtlrNmbr(), obj);
    }
    public TbVdsCtlrDto getCtlrMap(Long vdsCtlrNmbr) {
        return this.ctlrMap.get(vdsCtlrNmbr);
    }

    public TbVdsCtlrDto putIpAddrMap(TbVdsCtlrDto obj) {
        return this.ipAddrMap.put(obj.getVdsCtlrIp(), obj);
    }
    public TbVdsCtlrDto getIpAddrMap(String ipAddr) {
        return this.ipAddrMap.get(ipAddr);
    }

    public TbVdsCtlrDto putChannelMap(TbVdsCtlrDto obj) {
        return this.channelMap.put(obj.getChannel(), obj);
    }
    public TbVdsCtlrDto getChannelMap(Channel channel) {
        return this.channelMap.get(channel);
    }

}
