package com.hdkj.lt.bf.controller;

import com.hdkj.lt.bf.entity.dto.CustomerAccountDTO;
import com.hdkj.lt.bf.entity.vo.BreakerAreaVO;
import com.hdkj.lt.bf.entity.vo.PlanConfirmStateVO;
import com.hdkj.lt.bf.entity.vo.SwitchByUserVO;
import com.hdkj.lt.bf.service.FhzgFaultGenerateGraphService;
import com.hdkj.lt.core.bizms.modle.dto.EventQueryDTO;
import com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO;
import com.hdkj.lt.core.mvc.BaseController;
import com.hdkj.hussar.ApiResponse;
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;

import java.util.List;

/**
 * 成图服务
 *
 * @author zhuzhe
 * @since 2025-05-22
 */
@Slf4j
@RestController
@RequestMapping("/fhzgFaultGenerateGraph")
@RequiredArgsConstructor
public class FhzgFaultGenerateGraphController extends BaseController {

    private final FhzgFaultGenerateGraphService fhzgGenerateGraph;

    /**
     * 通过停电范围查询开关
     * @param dto
     * @return
     */
    @PostMapping("/getSwitchListByOutArea")
    @ApiOperation(value = "通过停电范围查询开关")
    public ApiResponse<List<BreakerAreaVO>> getSwitchListByOutArea(@RequestBody EventQueryDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("故障ID不能为空");
        }
        List<BreakerAreaVO> breakerList = fhzgGenerateGraph.getSwitchListByOutArea(dto);

        return ApiResponse.success(breakerList);
    }

    /**
     * 查询转供范围开关段
     * @param dto
     * @return
     */
    @PostMapping("/getSwitchListByTransferSection")
    @ApiOperation(value = "查询转供范围开关段")
    public ApiResponse<List<BreakerAreaVO>> getSwitchListByTransferSection(@RequestBody EventQueryDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("故障ID不能为空");
        }
        List<BreakerAreaVO> breakerList = fhzgGenerateGraph.getSwitchListByTransferSection(dto);

        return ApiResponse.success(breakerList);
    }

    /**
     * 根据用户查询开关
     * @param dto
     * @return
     */
    @PostMapping("/getSwitchByCustomer")
    @ApiOperation(value = "根据用户查询开关")
    public ApiResponse<SwitchByUserVO> getSwitchByCustomer(@RequestBody CustomerAccountDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getCustomerId() == null) {
            return fail("用户ID不能为空");
        }
        SwitchByUserVO switchVO = fhzgGenerateGraph.getSwitchByCustomer(dto);

        return ApiResponse.success(switchVO);
    }


    /**
     * 通过配变查上一级开关
     * @param dto
     * @return
     */
    @PostMapping("/getSwitchByDevice")
    @ApiOperation(value = "根据配变查询开关")
    public ApiResponse<SwitchByUserVO> getSwitchByDevice(@RequestBody CustomerAccountDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getTransformerNo() == null) {
            return fail("配变不能为空");
        }
        SwitchByUserVO switchVO = fhzgGenerateGraph.getSwitchByDevice(dto);

        return ApiResponse.success(switchVO);
    }

    /**
     * 转供路径概述，查询开关段
     * @param dto
     * @return
     */
    @PostMapping("/getPathOverviewSwitch")
    @ApiOperation(value = "转供路径概述查询开关段")
    public ApiResponse<List<BreakerAreaVO>> getPathOverviewSwitch(@RequestBody SchemeQueryDTO dto) {

        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getSchemeId() == null) {
            return fail("方案ID不能为空");
        }
        List<BreakerAreaVO> breakerAreaList = fhzgGenerateGraph.getPathOverviewSwitch(dto);

        return ApiResponse.success(breakerAreaList);
    }

    @PostMapping("/getPlanConfirmState")
    @ApiOperation(value = "查询故障确认状态")
    public ApiResponse<PlanConfirmStateVO> getPlanConfirmState(@RequestBody SchemeQueryDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("故障ID不能为空");
        }
        PlanConfirmStateVO breakerArea = fhzgGenerateGraph.getPlanConfirmState(dto);

        return ApiResponse.success(breakerArea);
    }

}
