package com.handong.smartservice.service;

import com.handong.smartservice._AG;
import com.handong.smartservice.component.CtResponse;
import com.handong.smartservice.component.ErrorCode;
import com.handong.smartservice.mapper.OperatingHistoryMapper;
import com.handong.smartservice.mapper.VocMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service
public class OperatingHistoryService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final OperatingHistoryMapper operatingHistoryMapper;


    public OperatingHistoryService(OperatingHistoryMapper operatingHistoryMapper) {
        this.operatingHistoryMapper = operatingHistoryMapper;
    }

    public Map<String, Object> getOperatingHistoryList(Boolean is_excel, Long offset, Long limit, String date_start, String date_end,
                Long type, String action) {
        Map<String, Object> mapResult = new HashMap<>();

        List<Map<String, Object>> listMap = (List<Map<String, Object>>)operatingHistoryMapper.selectOperatingHistory(false, is_excel, offset, limit, 
            date_start, date_end, type, action);
        mapResult.put("list", listMap);
        
        Long totalCount = _AG.getNumberFromQuery("COUNT(*)", operatingHistoryMapper.selectOperatingHistory(true, is_excel, offset, limit, 
            date_start, date_end, type, action));
        mapResult.put("totalCount", totalCount);
        mapResult.put("offset", offset);
        return mapResult;
    }

    public CtResponse add(Long type, String action, Long gid) {
        CtResponse result = new CtResponse();

        operatingHistoryMapper.insertOperatingHistory(type, action, gid);
        
        return result;
    }
}
