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

import com.hdkj.fhzg.optimization.request.FeederRequest;
import com.hdkj.fhzg.optimization.response.FeederGroupTreeNode;
import com.hdkj.hussar.ApiResponse;
import com.hdkj.lt.bf.application.FeederGroupApplication;
import com.hdkj.lt.bf.entity.vo.BreakerAreaVO;
import com.hdkj.lt.bf.entity.vo.XlRelVO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
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 15:10
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/feederGroup")
@RequiredArgsConstructor
public class FeederGroupController {

    private final FeederGroupApplication FeederGroupApplication;

    /**
     * 接线组索引树
     * 5/25：去掉接线组层级 改成 地市-区县-变电站-线路
     * @return
     */
    @PostMapping("/getFeederGroupTree")
    public ApiResponse<List<FeederGroupTreeNode>> getCountryStatistic() {
        List<FeederGroupTreeNode> feederGroupTree = FeederGroupApplication.getFeederGroupTree();
        return ApiResponse.success(feederGroupTree);
    }

    /**
     * 获取接线组联络开关列表
     *
     * @return
     */
    @PostMapping("/getFeederGroupContactSwitchList")
    public ApiResponse<List<XlRelVO>> getFeederGroupContactSwitchList(@RequestBody FeederRequest request) {
        List<XlRelVO> xlRelList = FeederGroupApplication.getFeederGroupContactSwitchList(request.getFeederId());
        return ApiResponse.success(xlRelList);
    }

    /**
     * 通过接线组ID查询默认态开关段
     * @param request
     * @return
     */
    @PostMapping("/getOverviewSwitchByFeederGroupId")
    @ApiOperation(value = "通过接线组ID查询默认态开关段")
    public ApiResponse<List<List<BreakerAreaVO>>> getOverviewSwitchByFeederGroupId(@RequestBody FeederRequest request) {
        boolean assertFlag = ObjectUtils.isNotEmpty(request) && StringUtils.isNotEmpty(request.getFeederId());
        Assert.isTrue(assertFlag, "线路ID不允许为空!");
        return ApiResponse.success(FeederGroupApplication.getOverviewSwitchByFeederGroupId(request.getFeederId()));
    }


}
