package com.its.web.service.common;

import com.its.web.dto.common.CodeDto;
import com.its.web.dto.common.ConnStatisticsDto;
import com.its.web.dto.common.TbWwwOrgDto;
import com.its.web.mapper.its.common.CommonMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Slf4j
@RequiredArgsConstructor
@Service
public class CommonService {
    private final CommonMapper mapper;

    /**
     * 공공기관 사이트 URL
     * @return List<TbWwwOrgDto>
     */
    public List<TbWwwOrgDto> findAllOrganization() {
        return this.mapper.findAllOrganization();
    }

    /**
     * Day Code 리스트
     * @return List<CodeDto>
     */
    public List<CodeDto> findDayList() {
        return this.mapper.findDayList();
    }

    /**
     * 접속자 조회 통계
     * @return List<ConnStatisticsDto>
     */
    public List<ConnStatisticsDto> getConnStatistics(Map<String, String> paramMap) {
        String type = paramMap.get("type");
        if ("week".equals(type)) {
            return this.mapper.getConnWeekStatistics(paramMap);
        }
        else if ("month".equals(type)) {
            return this.mapper.getConnMonthStatistics(paramMap);
        }
        return this.mapper.getConnStatistics(paramMap);
    }

    /**
     * 접속자 이력 등록
     * @return DB 등록 수
     */
    public int insertConnHs() { return this.mapper.insertConnHs(); }


}
