package com.hz.pm.api.expert.controller;


import com.ningdatech.log.annotation.WebLog;
import com.hz.pm.api.expert.manage.ExpertReviewManage;
import com.hz.pm.api.expert.model.req.ExpertReviewDetailReq;
import com.hz.pm.api.expert.model.vo.ExpertReviewDetailVO;
import com.hz.pm.api.expert.model.vo.ProjectReviewDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author WendyYang
 * @since 2023-02-15
 */
@RestController
@AllArgsConstructor
@Api(tags = "专家评审")
@RequestMapping("/api/v1/expertReview")
public class ExpertReviewController {

    private final ExpertReviewManage expertReviewManage;

    @PostMapping("/save")
    @ApiOperation("填写评审意见")
    @WebLog("填写评审意见")
    public void expertReview(@RequestBody @Valid ExpertReviewDetailReq req) {
        expertReviewManage.expertReview(req);
    }

    @GetMapping("/detail/{meetingId}/{projectId}/{userId}")
    @ApiOperation("获取专家评审详情")
    @WebLog("获取专家评审详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "专家ID"),
            @ApiImplicitParam(name = "projectId", value = "项目ID")
    })
    public ExpertReviewDetailVO getExpertReviewDetail(@PathVariable Long userId,
                                                      @PathVariable Long projectId,
                                                      @PathVariable Long meetingId) {
        return expertReviewManage.getExpertReviewDetail(userId, projectId, meetingId);
    }

    @GetMapping("/listForGroupLeader/{projectId}/{meetingId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID"),
            @ApiImplicitParam(name = "meetingId", value = "会议ID")
    })
    @ApiOperation("查看组员评审意见")
    @WebLog("查看组员评审意见")
    public List<ExpertReviewDetailVO> listForGroupLeader(@PathVariable Long meetingId,
                                                         @PathVariable Long projectId) {
        return expertReviewManage.listReviews(projectId, meetingId, true);
    }

    @GetMapping("/list/{projectId}/{meetingId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID"),
            @ApiImplicitParam(name = "meetingId", value = "会议ID")
    })
    @ApiOperation("查看项目某次会议的所有评审意见")
    @WebLog("查看项目某次会议的所有评审意见")
    public List<ExpertReviewDetailVO> list(@PathVariable Long meetingId,
                                           @PathVariable Long projectId) {
        return expertReviewManage.listReviews(projectId, meetingId, false);
    }

    @GetMapping("/detail/{projectCode}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectCode", value = "项目编号"),
    })
    @ApiOperation("查看项目的所有评审意见")
    @WebLog("查看项目的所有评审意见")
    public ProjectReviewDetailVO projectExpertReviewDetail(@PathVariable String projectCode) {
        return expertReviewManage.projectExpertReviewDetail(projectCode);
    }

}
