package com.its.api.its.global;

import com.its.api.its.model.entity.vds.TbVdsCtlr;
import com.its.api.its.repository.vds.TbVdsCtlrRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@RequiredArgsConstructor
@Getter
@Component
public class VdsManager {

    private final TbVdsCtlrRepository repo;

    private static final ConcurrentHashMap<String, TbVdsCtlr> facility = new ConcurrentHashMap<>();

    @PostConstruct
    void init() {
        load();
    }

    public void load() {

        List<TbVdsCtlr> objList = repo.findAll();
        objList.forEach(obj -> {
            facility.put(obj.getCtlrMngmNmbr(), obj);
        });
        log.info("=== {}", facility);
    }

    public static TbVdsCtlr get(String id) {
        return facility.get(id);
    }
}
