package cn.cslg.pas.controller;


import cn.cslg.pas.common.core.annotation.Permission;
import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.vo.TemplateConditionVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.domain.ReportTemplate;
import cn.cslg.pas.service.ReportTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 模板表 前端控制器
 * </p>
 *
 * @author 王岩
 * @since 2022-03-31
 */
@Tag(name = "报告模板")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/report/template")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ReportTemplateController {
    private final ReportTemplateService reportTemplateService;
    
//    @checkAuth(FunId = "/workspace/folder/analyticSystem/templateManager/check")
    @Permission(roles = {2})
    @GetMapping("list")
    @Operation(summary = "模板列表")
    public String getList(TemplateConditionVO params) {
        return Response.success(reportTemplateService.getPageList(params));
    }

    @GetMapping("{id}")
    @Operation(summary = "根据ID获取模板")
    public String getById(@PathVariable Integer id) {
        return Response.success(reportTemplateService.getTemplateById(id));
    }

    @checkAuth(FunId = "/workspace/folder/analyticSystem/templateManager/add")
    @Permission(roles = {2})
    @PostMapping("add")
    @Operation(summary = "选择模板")
    public String add(MultipartFile file, ReportTemplate reportTemplate) {
        return reportTemplateService.add(file, reportTemplate);
    }

    @checkAuth(FunId = "/workspace/folder/analyticSystem/templateManager/modify")
    @PostMapping("edit")
    @Permission(roles = {2})
    @Operation(summary = "编辑模板")
    public String edit(MultipartFile file, ReportTemplate reportTemplate) {
        return reportTemplateService.edit(file, reportTemplate);
    }

    @checkAuth(FunId = "/workspace/folder/analyticSystem/templateManager/delete")
    @PostMapping("delete")
    @Permission(roles = {2})
    @Operation(summary = "删除模板")
    public String delete(Integer id) {
        return reportTemplateService.delete(id);
    }
}

