package com.eactive.eai.rms.onl.apim.portalstatistics;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDate;
import java.util.Map;

@Controller
public class PortalStatisticsOrgTableManController {

    private final PortalStatisticsOrgTableManService portalStatisticsOrgTableManService;

    public PortalStatisticsOrgTableManController(PortalStatisticsOrgTableManService portalStatisticsOrgTableManService) {
        this.portalStatisticsOrgTableManService = portalStatisticsOrgTableManService;
    }

    @GetMapping(value = "/onl/apim/portalstatistics/portalStatisticsOrgTableMan.view")
    public void view() {
        // view
    }

    @PostMapping(value = "/onl/apim/portalstatistics/portalStatisticsOrgTableMan.json", params = "cmd=LIST")
    public ResponseEntity<Map<String, Object>> selectStatisticsList(
            @RequestParam @DateTimeFormat(pattern = "yyyyMMdd") LocalDate startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyyMMdd") LocalDate endDate) {

        Map<String, Object> result = portalStatisticsOrgTableManService.selectStatisticsList(startDate, endDate);
        return ResponseEntity.ok(result);
    }
}