package com.hdkj.lt.mq.controller;

import com.hdkj.hussar.ApiResponse;
import com.hdkj.lt.mq.entity.dto.AnalyzeDecudeParamDTO;
import com.hdkj.lt.mq.listener.RocketConsumerOutageEventListener;
import com.hdkj.lt.mq.listener.RocketConsumerSimulationPlatformListener;
import com.hdkj.lt.mq.service.fault.AcceptFaultPowerCutService;
import com.hdkj.lt.mq.service.fault.FaultFhzgReasoningPlatformService;
import com.hdkj.lt.mq.service.fault.IAnalysisFaultTransferResultService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;


/**
 * @author luorui
 * @date 2025/5/25 10:58
 * <p>
 * 模拟故障停电数据接入
 */
@Slf4j
@RestController
@RequestMapping("test")
@RequiredArgsConstructor
public class AcceptFaultPowerCutController {

    private final AcceptFaultPowerCutService acceptFaultPowerCutService;
    private final FaultFhzgReasoningPlatformService faultFhzgReasoningPlatformService;
    private final IAnalysisFaultTransferResultService analysisFaultTransferResultService;
    private final RocketConsumerSimulationPlatformListener rocketConsumerSimulationPlatformListener;
    private final RocketConsumerOutageEventListener rocketConsumerOutageEventListener;

    /**
     * 接收故障停电数据
     **/
    @PostMapping("/acceptFaultPowerCut")
    @ApiOperation(value = "接收计划停电数据")
    public ApiResponse<Boolean> acceptPlanPowerCut(@RequestBody String number) {
        rocketConsumerOutageEventListener.executeFunc(number, "1");
        return ApiResponse.success();
    }

    @PostMapping("/getAnalyzeParam")
    @ApiOperation(value = "故障停电 获取 计算推演平台参数")
    public ApiResponse<AnalyzeDecudeParamDTO> getAnalyzeParam(@RequestBody Long faultId) {
        AnalyzeDecudeParamDTO analyzeParam = faultFhzgReasoningPlatformService.getAnalyzeParam(faultId);

        return ApiResponse.success(analyzeParam);
    }

    @PostMapping("/executeFunc")
    @ApiOperation(value = "调用推演平台获取结果")
    public ApiResponse<AnalyzeDecudeParamDTO> executeFunc(@RequestBody Long faultId) {
        rocketConsumerSimulationPlatformListener.executeFunc(faultId, "2");
        return ApiResponse.success();
    }

    @PostMapping("/executeFuncPlan")
    @ApiOperation(value = "调用推演平台获取结果")
    public ApiResponse<AnalyzeDecudeParamDTO> executeFuncPlan(@RequestBody Long planId) {
        rocketConsumerSimulationPlatformListener.executeFunc(planId, "1");
        return ApiResponse.success();
    }

    @PostMapping("/analysisFaultTransferResult")
    @ApiOperation(value = "解析转供方案信息")
    public ApiResponse<Boolean> analysisFaultTransferResult(@RequestBody Long faultId) {
        analysisFaultTransferResultService.analysisFaultTransferResult(faultId);
        return ApiResponse.success();
    }
}
