package com.ningdatech.pmapi.expert.controller;


import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.expert.manage.ReviewTemplateSettingsManage;
import com.ningdatech.pmapi.expert.model.req.ReviewTemplateReq;
import com.ningdatech.pmapi.expert.model.vo.ReviewTemplateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
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-14
 */
@RestController
@AllArgsConstructor
@Api(tags = "评审模版配置")
@RequestMapping("/api/v1/reviewTemplateSettings")
public class ReviewTemplateSettingsController {

    private final ReviewTemplateSettingsManage reviewTemplateSettingsManage;

    @GetMapping("/template/{templateType}/{regionCode}")
    @ApiOperation("根据模版类型获取模版")
    public ReviewTemplateVO getReviewTemplateByType(@PathVariable Integer templateType, @PathVariable String regionCode) {
        return reviewTemplateSettingsManage.getReviewTemplateSettings(templateType, regionCode);
    }

    @PostMapping("/modify")
    @ApiOperation("修改或保存模版配置")
    @WebLog("修改或保存模版配置")
    public void modifyReviewTemplateSettings(@RequestBody @Valid ReviewTemplateReq req) {
        reviewTemplateSettingsManage.saveOrUpdate(req);
    }

    @GetMapping("/template")
    @ApiModelProperty("根据模版ID获取评审模版")
    @ApiImplicitParam(name = "templateId", defaultValue = "模版ID")
    public ReviewTemplateVO getTemplateById(@RequestParam Long templateId) {
        return reviewTemplateSettingsManage.getReviewTemplateSettings(templateId);
    }

    @GetMapping("/templates")
    @ApiModelProperty("（批量）根据模版ID获取评审模版")
    @ApiImplicitParam(name = "templateIds", defaultValue = "模版ID集合")
    public List<ReviewTemplateVO> getTemplateById(@RequestParam List<Long> templateIds) {
        return reviewTemplateSettingsManage.listReviewTemplateSettings(templateIds);
    }

}
