package net.educoder.ecsonar.controller;

import net.educoder.ecsonar.model.RollPage;
import net.educoder.ecsonar.model.api.QualityInspect;
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
import net.educoder.ecsonar.model.api.QualityInspectResultData;
import net.educoder.ecsonar.model.dto.AnalyseDetailDTO;
import net.educoder.ecsonar.model.dto.AnalyseDetailListDTO;
import net.educoder.ecsonar.model.dto.CodeDetailDTO;
import net.educoder.ecsonar.model.dto.ProblemAnalysisDTO;
import net.educoder.ecsonar.model.vo.*;
import net.educoder.ecsonar.services.GraduationProjectQualityInspectService;
import net.educoder.ecsonar.services.QualityInspectService;
import net.educoder.ecsonar.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author: youys
 * @Date: 2023/8/30
 * @Description: 毕设质量分析接口控制器
 */

@RestController
@RequestMapping("/graduation/project")
public class GraduationProjectController {


    @Resource
    private GraduationProjectQualityInspectService graduationProjectQualityInspect;

    @Resource
    private QualityInspectService qualityInspectService;


    /**
     * 质量检测
     *
     * @param qualityInspectVOList
     * @return
     */
    @PostMapping("/qualityInspect")
    public ResponseResult graduationQualityInspect(@RequestBody List<GraduationProjectQualityInspectVO> qualityInspectVOList) {
        QualityInspect qualityInspect = graduationProjectQualityInspect.graduationProjectQualityInspect(qualityInspectVOList);
        return ResponseResult.success(qualityInspect);
    }

    /**
     * 质量检测结果查询
     *
     * @param graduationQualityInspectResultQueryVO
     * @return
     */
    @PostMapping(value = "qualityInspectResultQuery")
    public ResponseResult graduationQualityInspectResultQuery(@RequestBody GraduationQualityInspectResultQueryVO graduationQualityInspectResultQueryVO) {
        QualityInspectIsCompleted isCompleted = graduationProjectQualityInspect.qualityInspectIsCompleted(graduationQualityInspectResultQueryVO.getTaskId());
        if (isCompleted.getCompleted() != 1) {
            return ResponseResult.error("质量检测正在处理中");
        }

        RollPage<QualityInspectResultData> result = graduationProjectQualityInspect.qualityInspectResultQuery(graduationQualityInspectResultQueryVO);
        return ResponseResult.success(result);
    }


    /**
     * 分析详情
     *
     * @return
     */
    @GetMapping("/analyseDetail")
    public ResponseResult<AnalyseDetailDTO> analyseDetail(@RequestParam("taskDetailId") String taskDetailId) {
        AnalyseDetailDTO analyseDetailDTO = graduationProjectQualityInspect.getAnalyseDetail(taskDetailId);
        return ResponseResult.success(analyseDetailDTO);
    }

    /**
     * 分析详情列表
     *
     * @return
     */
    @GetMapping("/analyseDetailList")
    public ResponseResult analyseDetailList(@Valid GraduationProjectAnalyseDetailListVO analyseDetailListVO) {
        RollPage<AnalyseDetailListDTO> rollPage = graduationProjectQualityInspect.getAnalyseDetailList(analyseDetailListVO);
        return ResponseResult.success(rollPage);
    }


    /**
     * 问题分析
     *
     * @return
     */
    @GetMapping("/problemAnalysis")
    public ResponseResult problemAnalysis(@RequestParam Integer ruleId) {
        ProblemAnalysisDTO problemAnalysis = qualityInspectService.getProblemAnalysis(ruleId);
        return ResponseResult.success(problemAnalysis);
    }


    /**
     * 代码详情
     *
     * @return
     */
    @GetMapping("/codeDetail")
    public ResponseResult<CodeDetailDTO> codeDetail(@Valid CodeDetailVO codeDetailVO) {
        CodeDetailDTO codeDetail = qualityInspectService.getCodeDetail(codeDetailVO);
        return ResponseResult.success(codeDetail);
    }


}
