package incheon.sgp.rst.service.impl;

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


import org.springframework.stereotype.Service;

import incheon.sgp.rst.mapper.RstLasuMapper;
import incheon.sgp.rst.service.RstLasuService;
import incheon.sgp.rst.vo.RstLasuResultVO;
import incheon.sgp.rst.vo.RstLasuSpfcVO;
import incheon.sgp.rst.vo.RstLasuSummaryVO;
import incheon.sgp.rst.vo.RstLasuTrendVO;

/**
 * @ClassName : RstLasuServiceImpl.java
 * @Description : 토지이용현황 통계 서비스 구현체
 * @author : 이주훈
 * @since : 2025.11.20
 * @version : 1.0
 */
@Service
public class RstLasuServiceImpl  implements RstLasuService {

	// 매퍼 주입
    private final RstLasuMapper rstLasuMapper; 

    // 매퍼 생성자 주입
    public RstLasuServiceImpl(RstLasuMapper rstLasuMapper) {
        this.rstLasuMapper = rstLasuMapper;
    }
    
    // 최신 기준연월 가져오기
    @Override
    public List<String> selectCrtrYrList() throws Exception {
        return rstLasuMapper.selectCrtrYrList();
    }
    
    // 토지이용현황 통계 가져오기
    @Override 
    public RstLasuResultVO getLasuStats(String crtrYear, String sggCd, String emdCd, String liCd) {

        Map<String,Object> params = new HashMap<>();
        params.put("crtrYear", crtrYear);
        params.put("sggCd", sggCd);
        params.put("emdCd", emdCd);
        params.put("liCd", liCd);

        RstLasuSummaryVO summary = rstLasuMapper.selectSummary(params);
        List<RstLasuSpfcVO> spfcList = rstLasuMapper.selectSpfcList(params);
        RstLasuTrendVO trend = rstLasuMapper.selectTrend(params);

        RstLasuResultVO result = new RstLasuResultVO();
        result.setStatus("success");
        result.setSummary(summary);
        result.setSpfcList(spfcList);
        result.setTrend(trend);

        return result;
    }
    
}
