package com.hdkj.lt.bf.controller.optimization;

import com.hdkj.fhzg.optimization.request.MaintOrgRequest;
import com.hdkj.fhzg.optimization.request.MetricsRequest;
import com.hdkj.fhzg.optimization.response.OperationMetrics;
import com.hdkj.fhzg.optimization.response.StationGridMetrics;
import com.hdkj.fhzg.optimization.response.StationSvgResponse;
import com.hdkj.hussar.ApiResponse;
import com.hdkj.lt.bf.application.OptimizationApplication;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author rj
 * @date 2026/5/22 17:18
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/optimization")
@RequiredArgsConstructor
public class OptimizationController {

    private final OptimizationApplication optimizationApplication;


    /**
     * 获取运行优化指标数据
     *
     * @return
     */
    @PostMapping("/getStationOperationMetrics")
    public ApiResponse<OperationMetrics> getStationOperationMetrics(@RequestBody MetricsRequest request) {
        if (StringUtils.isNotBlank(request.getMaintOrgId())) {
            return ApiResponse.success(optimizationApplication.getStationOperationMetrics(request.getMaintOrgId()));
        } else {
            return ApiResponse.success(optimizationApplication.getFeederOperationMetrics(request.getFeederId()));
        }
    }

    /**
     * 获取网架优化指标数据
     *
     * @return
     */
    @PostMapping("/getStationGridMetrics")
    public ApiResponse<StationGridMetrics> getStationGridMetrics(@RequestBody MetricsRequest request) {
        StationGridMetrics stationGridMetrics = optimizationApplication.getStationGridMetrics(request.getMaintOrgId());
        return ApiResponse.success(stationGridMetrics);
    }




    /**
     * 获取站间联络图渲染数据
     *
     * @return
     */
    @PostMapping("/getStationSvg")
    public ApiResponse<List<StationSvgResponse>> getStationSvg(@RequestBody MaintOrgRequest request) {
        return ApiResponse.success(optimizationApplication.getStationSvg(request.getMaintOrg()));
    }


}
