package com.usky.vpp.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.vpp.service.VppCapabilityEvalService;
import com.usky.vpp.service.vo.CapabilityEvalSummaryVO;
import com.usky.vpp.service.vo.CapabilityHistoryVO;
import com.usky.vpp.service.vo.CapabilityLoadCurveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 可调能力评估接口
 * <p>网关前缀: /prod-api/service-vpp/capability-eval</p>
 */
@RestController
@RequestMapping("/capability-eval")
public class CapabilityEvalController {

    @Autowired
    private VppCapabilityEvalService vppCapabilityEvalService;

    /**
     * 顶部汇总统计
     * <p>支持按 siteId 筛选；返回总资源/负荷类/储能类/发电类户数与容量，及最大上下调能力。</p>
     */
    @GetMapping("/summary")
    public ApiResult<CapabilityEvalSummaryVO> summary(@RequestParam(value = "siteId", required = false) Long siteId) {
        return ApiResult.success(vppCapabilityEvalService.getSummary(siteId));
    }

    /**
     * 可调能力曲线（基线负荷 vs 实际负荷）
     * <p>默认统计当天，每 10 分钟一个点（00:00 ~ 23:50）。</p>
     */
    @GetMapping("/load-curve")
    public ApiResult<CapabilityLoadCurveVO> loadCurve(@RequestParam(value = "siteId", required = false) Long siteId,
                                                      @RequestParam(value = "date", required = false) String date) {
        return ApiResult.success(vppCapabilityEvalService.getLoadCurve(siteId, date));
    }

    /**
     * 历史响应记录（分页）
     * <p>按站点下资源参与的需求响应事件倒序展示。</p>
     */
    @GetMapping("/history")
    public ApiResult<CommonPage<CapabilityHistoryVO>> history(@RequestParam(value = "siteId", required = false) Long siteId,
                                                            @RequestParam(required = false) Map<String, Object> params) {
        return ApiResult.success(vppCapabilityEvalService.pageHistory(siteId, params));
    }
}
