package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.dto.AvoidDesignDirectionDTO;
import cn.cslg.report.common.model.vo.AvoidDesignWholeVO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.exception.XiaoShiException;
import cn.cslg.report.service.IAvoidDesignDirectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 回避设计方案的Controller层
 *
 * @Author chenyu
 * @Data 2023/2/2
 */
@Tag(name = "回避设计方案")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(Constants.REPORT_API + "/avoidDesignDirections")
public class AvoidDesignDirectionController {
    private final IAvoidDesignDirectionService avoidDesignDirectionService;

    @Operation(summary = "新增回避设计方案")
    @PostMapping("/addAvoidDesignDirection")
    public String addAvoidDesignDirection(@RequestBody AvoidDesignDirectionDTO avoidDesignDirectionDTO) {
        log.info("开始处理【新增回避设计方案】的请求，参数为：{}", avoidDesignDirectionDTO);
        try {
            avoidDesignDirectionService.addAvoidDesignDirection(avoidDesignDirectionDTO);
        } catch (XiaoShiException e) {
            return Response.error(e.getMessage());
        }
        return Response.success(1);
    }

    @Operation(summary = "查询回避设计方案")
    @GetMapping("/getAvoidDesignDirection")
    public String getAvoidDesignDirection(Integer reportId) throws IOException {
        log.info("开始处理【查询回避设计方案】的请求，参数为：{}", reportId);
        AvoidDesignWholeVO queryResult = avoidDesignDirectionService.getAvoidDesignDirection(reportId);
        return Response.success(queryResult);
    }

}
