package com.base.plan.controller;

import com.base.core.utiles.ListUtils;
import com.base.orbit.domain.AjaxResult;
import com.base.orbit.web.Result;
import com.base.plan.model.dto.QueryPassDTO;
import com.base.plan.model.dto.QueryUpdateWindowDTO;
import com.base.plan.model.dto.request.QueryWindowListDTO;
import com.base.plan.service.AlgSchemeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cxl
 * @since 2022-06-24
 */
@RestController
@RequestMapping("/api/scheme/v1")
@Api(value = "需求筹划")
public class AlgSchemController {

    @Autowired
    AlgSchemeService algSchemeService;

    @ApiOperation(value = "方案评估信息列表查询")
    @GetMapping("/list")
    public AjaxResult getSchemeList() {
        return AjaxResult.success(algSchemeService.getStepList());
    }

    @ApiOperation(value = "筹划方案列表查询")
    @GetMapping("/step/detail/list")
    public AjaxResult getStepList() {
        return AjaxResult.success(algSchemeService.getIsUsedStepDetailList());
    }

    @ApiOperation(value = "侦察窗口列表查询")
    @GetMapping("/step/window/list")
    public AjaxResult getWindowList(QueryWindowListDTO queryWindowListDTO) {
        return AjaxResult.success(algSchemeService.getWindowList(queryWindowListDTO));
    }

    @ApiOperation(value = "地面站列表查询")
    @GetMapping("/step/window/pass/list")
    public AjaxResult getPassList(QueryPassDTO reqDTO) {
        return AjaxResult.success(algSchemeService.getPassList(reqDTO));
    }

    @ApiOperation(value = "地面站冲突列表查询")
    @GetMapping("/step/pass/mutex/list")
    public AjaxResult queryStationMutexDTOList() {
        return AjaxResult.success(algSchemeService.getStationMutexDTOList(null));
    }

    @ApiOperation(value = "卫星冲突列表查询")
    @GetMapping("/step/satellite/mutex/list")
    public AjaxResult querySatelliteMutexDTOList() {
        return AjaxResult.success(algSchemeService.getSatelliteMutexDTOList(null));
    }

    @ApiOperation(value = "修改筹划窗口")
    @PostMapping("/step/window/relation/update")
    public AjaxResult updateWindowList(@RequestBody List<QueryUpdateWindowDTO> reqDTO) {

        for (QueryUpdateWindowDTO req : reqDTO) {
            if (ListUtils.isNoE(req.getWindowRelationDTOList())) {
                return AjaxResult.error(500, "调整方案集合不能为空！");
            }
        }
        algSchemeService.updateWindowList(reqDTO);
        return AjaxResult.success();
    }

    @ApiOperation(value = "确认筹划窗口")
    @PostMapping("/step/window/confirm")
    public Result confirmScheme(@RequestBody List<String> stepList) {
        algSchemeService.confirmScheme(stepList);
        return Result.success();
    }

    @ApiOperation(value = "任务监视")
    @PostMapping("/step/window/taskMonitor")
    public AjaxResult taskMonitor(@RequestBody QueryWindowListDTO queryWindowListDTO) {
        return algSchemeService.taskMonitor(queryWindowListDTO);
    }
}