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.DocTemplateCategoryPageReqVO;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateCategoryRespVO;
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateCategorySaveReqVO;
import com.zt.plat.module.base.service.doctemplate.DocTemplateCategoryService;
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-category")
@Validated
public class DocTemplateCategoryController {

    @Resource
    private DocTemplateCategoryService templateCategoryService;

    @PostMapping("/create")
    @Operation(summary = "创建模板分类")
    @PreAuthorize("@ss.hasPermission('base:template-category:create')")
    public CommonResult<Long> createTemplateCategory(@Valid @RequestBody DocTemplateCategorySaveReqVO createReqVO) {
        return success(templateCategoryService.createTemplateCategory(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新模板分类")
    @PreAuthorize("@ss.hasPermission('base:template-category:update')")
    public CommonResult<Boolean> updateTemplateCategory(@Valid @RequestBody DocTemplateCategorySaveReqVO updateReqVO) {
        templateCategoryService.updateTemplateCategory(updateReqVO);
        return success(true);
    }

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

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

    @GetMapping("/page")
    @Operation(summary = "获得模板分类分页")
    @PreAuthorize("@ss.hasPermission('base:template-category:query')")
    public CommonResult<PageResult<DocTemplateCategoryRespVO>> getTemplateCategoryPage(@Valid DocTemplateCategoryPageReqVO pageReqVO) {
        return success(templateCategoryService.getTemplateCategoryPage(pageReqVO));
    }

    @GetMapping("/list")
    @Operation(summary = "获得模板分类列表")
    @PreAuthorize("@ss.hasPermission('base:template-category:query')")
    public CommonResult<List<DocTemplateCategoryRespVO>> getTemplateCategoryList() {
        return success(templateCategoryService.getTemplateCategoryList());
    }

    @GetMapping("/tree")
    @Operation(summary = "获得模板分类树形结构")
    @PreAuthorize("@ss.hasPermission('base:template-category:query')")
    public CommonResult<List<DocTemplateCategoryRespVO>> getTemplateCategoryTree() {
        return success(templateCategoryService.buildTree());
    }

}
