package com.ga.api.controller.kpi;

import com.ga.api.service.kpi.ForecastKpiMonthlyService;
import com.ga.common.annotation.DataChangeLog;
import com.ga.common.annotation.RequirePermission;
import com.ga.common.model.ApiResponse;
import com.ga.common.model.PageResponse;
import com.ga.core.vo.kpi.ForecastKpiMonthlyResp;
import com.ga.core.vo.kpi.ForecastKpiMonthlySaveReq;
import com.ga.core.vo.kpi.ForecastKpiMonthlySearchParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "차월 KPI 예측")
@RestController
@RequestMapping("/api/forecast-kpi")
@RequiredArgsConstructor
public class ForecastKpiMonthlyController {

    private final ForecastKpiMonthlyService service;

    @GetMapping
    @Operation(summary = "예측 목록")
    @RequirePermission(menu = "FORECAST_KPI", perm = "READ")
    public ApiResponse<PageResponse<ForecastKpiMonthlyResp>> list(@ModelAttribute ForecastKpiMonthlySearchParam p) {
        return ApiResponse.ok(service.list(p));
    }

    @PostMapping("/regenerate")
    @Operation(summary = "차월 예측 재산출")
    @RequirePermission(menu = "FORECAST_KPI", perm = "EXECUTE")
    @DataChangeLog(menu = "FORECAST_KPI", table = "forecast_kpi_monthly")
    public ApiResponse<Integer> regenerate(@Valid @RequestBody ForecastKpiMonthlySaveReq req) {
        return ApiResponse.ok(service.regenerate(req));
    }
}
