package com.zt.plat.module.base.controller.admin.doctemplate;

import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplatePageReqVO;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateRespVO;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateSaveReqVO;
import com.zt.plat.module.base.service.doctemplate.DocTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

import static com.zt.plat.framework.common.pojo.CommonResult.success;

/**
 * 模板 Controller
 *
 * @author 系统生成
 */
@Tag(name = "管理后台 - 模板")
@RestController
@RequestMapping("/base/doc-template")
@Validated
public class DocTemplateController {

    @Resource
    private DocTemplateService templateService;

    @PostMapping("/create")
    @Operation(summary = "创建模板")
    @PreAuthorize("@ss.hasPermission('base:template:create')")
    public CommonResult<Long> createTemplate(@Valid @RequestBody DocTemplateSaveReqVO createReqVO) {
        return success(templateService.createTemplate(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新模板")
    @PreAuthorize("@ss.hasPermission('base:template:update')")
    public CommonResult<Boolean> updateTemplate(@Valid @RequestBody DocTemplateSaveReqVO updateReqVO) {
        templateService.updateTemplate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除模板")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:template:delete')")
    public CommonResult<Boolean> deleteTemplate(@RequestParam("id") Long id) {
        templateService.deleteTemplate(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得模板")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('base:template:query')")
    public CommonResult<DocTemplateRespVO> getTemplate(@RequestParam("id") Long id) {
        return success(templateService.getTemplate(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得模板分页")
    @PreAuthorize("@ss.hasPermission('base:template:query')")
    public CommonResult<PageResult<DocTemplateRespVO>> getTemplatePage(@Valid DocTemplatePageReqVO pageReqVO) {
        return success(templateService.getTemplatePage(pageReqVO));
    }

    @GetMapping("/list")
    @Operation(summary = "获得模板列表")
    @PreAuthorize("@ss.hasPermission('base:template:query')")
    public CommonResult<List<DocTemplateRespVO>> getTemplateList() {
        return success(templateService.getTemplateList());
    }

}
