package com.m2pool.manage.controller;

import com.m2pool.common.core.Result.R;
import com.m2pool.common.core.web.page.TableDataInfo;
import com.m2pool.common.security.annotation.Logical;
import com.m2pool.common.security.annotation.RequiresLogin;
import com.m2pool.common.security.annotation.RequiresRoles;
import com.m2pool.manage.dto.ManageCatalogueDocumentDto;
import com.m2pool.manage.dto.ManageCatalogueDto;
import com.m2pool.manage.dto.ManageDocumentDto;
import com.m2pool.manage.service.ManageDocumentsService;
import com.m2pool.manage.vo.ManageBaseVo;
import com.m2pool.manage.vo.ManageCatalogueVo;
import com.m2pool.manage.vo.ManageDocumentVo;
import com.m2pool.manage.vo.ManageSearchDocumentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 文档信息控制器类
 * @Date 2025/5/22 14:22
 * @Author yyb
 */
@RestController
@RequestMapping("/documents")
@Api(tags = "文档控制器类")
public class ManageDocumentsController {

    @Resource
    private ManageDocumentsService manageDocumentsService;


    @PostMapping("/getListDataByPage")
    @ApiOperation(value = "管理系统:分页+条件查询所有的文档 + 业务系统:按关键字搜索文章内容")
    //@RequiresLogin
    //@RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public TableDataInfo<ManageDocumentDto> getListDataByPage(@RequestBody ManageSearchDocumentVo manageSearchDocumentVo){
        return manageDocumentsService.getListDataByPage(manageSearchDocumentVo);
    }

    @PostMapping("/addDocument")
    @ApiOperation(value = "管理系统:新增文档")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<String> addDocument(@RequestBody ManageDocumentVo manageDocumentVo){
        return manageDocumentsService.addDocument(manageDocumentVo);
    }

    @PostMapping("/deleteDocument")
    @ApiOperation(value = "管理系统:删除文档")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<String> deleteDocument(@RequestBody ManageBaseVo manageBaseVo){
        return manageDocumentsService.deleteDocument(manageBaseVo);
    }

    @PostMapping("/updateDocument")
    @ApiOperation(value = "管理系统:修改文档")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<String> updateDocument(@RequestBody ManageDocumentVo manageDocumentVo){
        return manageDocumentsService.updateDocument(manageDocumentVo);
    }

    @PostMapping("/findDataInfo")
    @ApiOperation(value = "管理系统:获取文档详情，用于编辑修改文档 + 业务系统:根据id获取对应的文档详情内容")
    //@RequiresLogin
    //@RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<ManageDocumentDto> findDataInfo(@RequestBody ManageBaseVo manageBaseVo){
        return manageDocumentsService.findDataInfo(manageBaseVo);
    }
    //@PostMapping("/findDataById")
    //@ApiOperation(value = "业务系统:根据id获取对应的文档详情内容")
    //public R<ManageDocumentDto> findDataById(@RequestBody(required = false) ManageBaseVo manageBaseVo){
    //    return manageDocumentsService.findDataById(manageBaseVo);
    //}

    @PostMapping("/findCatalogueDocumentList")
    @ApiOperation(value = "业务系统:获取文档类型对应的文章列表")
    public TableDataInfo<ManageCatalogueDocumentDto> findCatalogueDocumentList(@RequestBody ManageCatalogueVo manageCatalogueVo){
        return manageDocumentsService.findCatalogueDocumentList(manageCatalogueVo);
    }

    @PostMapping("/findCatalogueList")
    @ApiOperation(value = "业务系统:获取文档目录列表 + 管理系统：目录下拉选择框")
    public R<List<ManageCatalogueDto>> findCatalogueList(@RequestBody ManageCatalogueVo manageCatalogueVo){
        return manageDocumentsService.findCatalogueList(manageCatalogueVo);
    }




    //@PostMapping("/searchDocument")
    //@ApiOperation(value = "业务系统:按关键字搜索文章内容")
    //public TableDataInfo<ManageDocumentDto> searchDocument(@RequestBody ManageSearchDocumentVo manageSearchDocumentVo){
    //    return manageDocumentsService.searchDocument(manageSearchDocumentVo);
    //}
}
