package com.its.vms.service;

import com.its.vms.dao.mapper.VmsFontMapper;
import com.its.vms.dto.TbVmsFontColrDto;
import com.its.vms.dto.TbVmsFontNameDto;
import com.its.vms.entity.TbVmsFontColr;
import com.its.vms.entity.TbVmsFontName;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
@RequiredArgsConstructor
public class VmsFontService {

    private final VmsFontMapper vmsFontMapper;

    public ConcurrentHashMap<Integer, TbVmsFontName> nameMap = new ConcurrentHashMap<>();
    public ConcurrentHashMap<Integer, TbVmsFontColr> colrMap = new ConcurrentHashMap<>();

    public void loadFontInfo() {
        loadFontNameInfo();
        loadFontColorInfo();
    }

    public void loadFontNameInfo() {
        try {
            List<TbVmsFontNameDto> infoList  = this.vmsFontMapper.selectFontName();
            log.info("VmsFontService.loadFontNameInfo(), {} EA", infoList.size());
            for (TbVmsFontNameDto dto : infoList) {
                TbVmsFontName obj = dto.toEntity();
                this.nameMap.put(obj.getVmsFontNameCd(), obj);
            }
        }
        catch (Exception e) {
            log.error("VmsFontService.loadFontNameInfo: {}", e.toString());
        }
    }

    public void loadFontColorInfo() {
        try {
            List<TbVmsFontColrDto> infoList  = this.vmsFontMapper.selectFontColr();
            log.info("VmsFontService.loadFontColorInfo(), {} EA", infoList.size());
            for (TbVmsFontColrDto dto : infoList) {
                TbVmsFontColr obj = dto.toEntity();
                this.colrMap.put(obj.getVmsFontColrCd(), obj);
            }
        }
        catch (Exception e) {
            log.error("VmsFontService.loadFontColorInfo: {}", e.toString());
        }
    }

}
