package com.its.api.its.global;

import com.its.api.its.model.entity.cctv.TbCctvCtlr;
import com.its.api.its.repository.cctv.TbCctvCtlrRepository;
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 CctvManager {

    private final TbCctvCtlrRepository repo;

    private static final ConcurrentHashMap<Long, TbCctvCtlr> facility = new ConcurrentHashMap<>();

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

    public void load() {

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

    public static TbCctvCtlr get(Long id) {
        return facility.get(id);
    }
}
