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.DocTemplateTagPageReqVO;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateTagRespVO;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateTagSaveReqVO;
import com.zt.plat.module.base.service.doctemplate.DocTemplateTagService;
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-tag")
@Validated
public class DocTemplateTagController {

    @Resource
    private DocTemplateTagService templateTagService;

    @PostMapping("/create")
    @Operation(summary = "创建标签")
    @PreAuthorize("@ss.hasPermission('base:template-tag:create')")
    public CommonResult<Long> createTemplateTag(@Valid @RequestBody DocTemplateTagSaveReqVO createReqVO) {
        return success(templateTagService.createTemplateTag(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新标签")
    @PreAuthorize("@ss.hasPermission('base:template-tag:update')")
    public CommonResult<Boolean> updateTemplateTag(@Valid @RequestBody DocTemplateTagSaveReqVO updateReqVO) {
        templateTagService.updateTemplateTag(updateReqVO);
        return success(true);
    }

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

    @GetMapping("/get")
    @Operation(summary = "获得标签")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('base:template-tag:query')")
    public CommonResult<DocTemplateTagRespVO> getTemplateTag(@RequestParam("id") Long id) {
        return success(templateTagService.getTemplateTag(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得标签分页")
    @PreAuthorize("@ss.hasPermission('base:template-tag:query')")
    public CommonResult<PageResult<DocTemplateTagRespVO>> getTemplateTagPage(@Valid DocTemplateTagPageReqVO pageReqVO) {
        return success(templateTagService.getTemplateTagPage(pageReqVO));
    }

    @GetMapping("/list")
    @Operation(summary = "获得标签列表")
    @PreAuthorize("@ss.hasPermission('base:template-tag:query')")
    public CommonResult<List<DocTemplateTagRespVO>> getTemplateTagList() {
        return success(templateTagService.getTemplateTagList());
    }

}
