/*
 * Copyright (c) 2021 LG Electronics Inc.
 * SPDX-License-Identifier: AGPL-3.0-only 
 */

package oss.fosslight.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oss.fosslight.CoTopComponent;
import oss.fosslight.common.CommonFunction;
import oss.fosslight.domain.VulnerabilityHistory;
import oss.fosslight.repository.VulnerabilityHistoryMapper;
import oss.fosslight.service.VulnerabilityHistoryService;

@Service
public class VulnerabilityHistoryServiceImpl extends CoTopComponent implements VulnerabilityHistoryService {
	//Mapper
	@Autowired VulnerabilityHistoryMapper vulnerabilityHistoryMapper;
	
	@Override
	public Map<String, Object> getVulnerabilityHistoryList(VulnerabilityHistory vulnerabilityHistory) {
		Map<String, Object> map = null;

		String filterCondition = CommonFunction.getFilterToString(vulnerabilityHistory.getFilters());
		
		if (!isEmpty(filterCondition)) {
			vulnerabilityHistory.setFilterCondition(filterCondition);
		}
		
		int records = vulnerabilityHistoryMapper.selectVulnerabilityHistoryTotalCount(vulnerabilityHistory);
		
		if (records > 0) {
			vulnerabilityHistory.setTotListSize(records);
			// Grid paging 처리를 위한 기본 param 설정 Map 생성(반드시 totlistsize를 set 하고 나서 생성해야함)
			map = getGridPagerMap(vulnerabilityHistory);
			map.put("rows", vulnerabilityHistoryMapper.selectVulnerabilityHistoryList(vulnerabilityHistory));
		}
		
		// TODO - 검토 필요함.
		return map == null ? new HashMap<String, Object>() : map;
	}
}
