package com.handong.smartservice.controller.api;

import com.handong.smartservice._AG;
import com.handong.smartservice.component.CtResponse;
import com.handong.smartservice.component.ErrorCode;
import com.handong.smartservice.service.OperatingHistoryService;
import com.handong.smartservice.service.VocService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/api")
class OperatingHistoryController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final OperatingHistoryService operatingHistoryService;


    public OperatingHistoryController(OperatingHistoryService operatingHistoryService) {
        this.operatingHistoryService = operatingHistoryService;
    }

    @RequestMapping(value = "/get-operating-history.do", method = RequestMethod.POST)
    public CtResponse getOperatingHistory(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> body) {
        logger.info("req: " + request.getRequestURI());

        CtResponse result = new CtResponse();

        Boolean is_excel = _AG.toBoolean(body.get("is_excel"));
        Long offset= _AG.toLong(body.get("offset"));
        Long limit = _AG.toLong(body.get("limit"));
        if (limit > 100)
            limit = 100L;

        String date_start = body.get("date_start");
        String date_end = body.get("date_end");
        Long type = _AG.toLong(body.get("type"));
        String action = body.get("action");
        
        Map<String, Object> mapResult = operatingHistoryService.getOperatingHistoryList(is_excel, offset, limit, date_start, date_end, type, action);
        result.put("result", mapResult);
        return result;
    }
}
