package com.its.op.global;

import com.its.op.entity.its.vms.TbVmsIfsc;
import com.its.op.dao.repository.its.vms.TbVmsIfscRepository;
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 VmsIfscManager {

    private final TbVmsIfscRepository repo;

    private static final ConcurrentHashMap<Long, TbVmsIfsc> ifsc = new ConcurrentHashMap<>();

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

    public void load() {

        List<TbVmsIfsc> objList = this.repo.findAll();
        objList.forEach(obj -> {
            ifsc.put(obj.getVmsIfscId(), obj);
        });
        //log.info("=== {}", ifsc);
    }

    public static TbVmsIfsc get(Long id) {
        if (id == null) {
            return null;
        }
        return ifsc.get(id);
    }

}
