package com.cpop.system.business.controller.backstage;

import com.cpop.core.base.entity.R;
import com.cpop.system.business.bo.MenuBo;
import com.cpop.system.business.bo.MenuListBo;
import com.cpop.system.business.service.MenuService;
import com.cpop.system.business.vo.MenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统菜单表 控制层。
 *
 * @author DB
 * @since 2023-10-19
 */
@RestController
@Tag(name = "菜单接口")
@RequestMapping("/backstage/menu")
public class BackstageMenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 获取系统菜单树列表
     * @author DB
     * @since 2023/09/07 15:48
     * @param bo 请求参数
     * @return com.cpop.core.base.R<java.util.List<MenuVo>>
     */
    @Operation(summary = "获取系统菜单树列表")
    @GetMapping("/getSysMenuTreeList")
    public R<List<MenuVo>> getSysMenuTreeList(MenuListBo bo) {
        List<MenuVo> list = menuService.getSysMenuTreeList(bo);
        return R.ok(list);
    }

    /**
     * 获取目录与菜单树
     * @author DB
     * @since 2023/09/07 17:41
     * @return com.cpop.core.base.R<java.util.List<com.cpop.oam.business.vo.MenuVo>>
     */
    @Operation(summary = "获取目录与菜单树")
    @GetMapping("/getDirectoryAndMenuTreeList")
    public R<List<MenuVo>> getDirectoryAndMenuTreeList() {
        List<MenuVo> list = menuService.getDirectoryAndMenuTreeList();
        return R.ok(list);
    }

    /**
     * 新增菜单
     * @author DB
     * @since 2023/09/07 17:45
     * @param bo 请求参数
     * @return com.cpop.core.base.R<java.lang.Void>
     */
    @Operation(summary = "新增菜单")
    @PostMapping("/insertSysMenu")
    public R<Void> insertSysMenu(@RequestBody @Validated MenuBo bo) {
        menuService.insertSysMenu(bo);
        return R.ok();
    }

    /**
     * 修改菜单
     * @param bo 请求参数
     * @author DB
     * @since 2023/5/10 16:01
     **/
    @Operation(summary = "修改菜单")
    @PutMapping("/updateSysMenu")
    public R<Void> updateSysMenu(@RequestBody @Validated MenuBo bo) {
        menuService.updateSysMenu(bo);
        return R.ok();
    }

    /**
     * 删除菜单
     * @param id 主键id
     * @author DB
     * @since 2023/5/10 16:01
     **/
    @Operation(summary = "删除菜单")
    @DeleteMapping("/removeSysMenu/{id}")
    public R<Void> removeSysMenu(@PathVariable String id) {
        menuService.removeSysMenu(id);
        return R.ok();
    }

}
