package org.wcs.serve.controller.app;

import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.menu.AddBaseMenuPermission;
import org.wcs.model.dto.serve.menu.AddMenuReq;
import org.wcs.model.dto.serve.menu.UpdateMenuReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.dto.serve.menu.QueryMenuReq;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.menu.MenuPermissionVo;
import org.wcs.model.vo.serve.menu.QueryMenuResp;
import org.wcs.serve.service.intf.IMenuService;

import java.util.List;

/**
 * 菜单相关控制器
 */
@RestController
@RequestMapping("/app/menu")
@ResponseBody
@RequiredArgsConstructor
public class MenuController {

    private final IMenuService menuService;

    /**
     * 查询菜单
     * @param queryMenuReq 查询菜单请求
     * @return 查询结果
     */
    @PostMapping("/queryMenu")
    public AppServeDataResponse<List<QueryMenuResp>> queryMenu(@RequestBody QueryMenuReq queryMenuReq) {
        return menuService.queryMenu(queryMenuReq);
    }

    /**
     * 添加一个菜单
     * @param addMenuReq 添加的数据
     * @return 结果
     */
    @PostMapping("/addMenu")
    public AppServeResponse addMenu(@RequestBody @Validated AddMenuReq addMenuReq) {
        return menuService.addMenu(addMenuReq);
    }

    /**
     * 删除一个菜单
     * @param menuId 菜单ID
     * @return 结果
     */
    @DeleteMapping("/deleteMenu/{menuId}")
    public AppServeResponse deleteMenu(@PathVariable @NotBlank(message = "菜单ID不能为空") String menuId) {
        return menuService.deleteMenu(menuId);
    }

    /**
     * 更新菜单
     * @param updateMenuReq 更新的数据
     * @return 结果
     */
    @PostMapping("/updateMenu")
    public AppServeResponse updateMenu(@RequestBody @Validated UpdateMenuReq updateMenuReq) {
        return menuService.updateMenu(updateMenuReq);
    }

    /**
     * 查询菜单权限
     * @param menuId 菜单ID
     * @return 菜单权限列表
     */
    @GetMapping("/queryMenuPermission/{menuId}")
    public AppServeDataResponse<List<MenuPermissionVo>> queryMenuPermission(@PathVariable String menuId) {
        return menuService.queryMenuPermission(menuId);
    }

    /**
     * 添加菜单权限
     * @param request 添加的数据
     * @return 添加结果
     */
    @PostMapping("/addBaseMenuPermission")
    public AppServeResponse addBaseMenuPermission(@RequestBody @Validated AddBaseMenuPermission request) {
        return menuService.addBaseMenuPermission(request);
    }

    /**
     * 删除菜单权限
     * @param permissionId 菜单权限ID
     * @return 删除结果
     */
    @DeleteMapping("/deleteBaseMenuPermission/{permissionId}")
    public AppServeResponse deleteBaseMenuPermission(@PathVariable @NotBlank(message = "权限ID不能为空") String permissionId) {
        return menuService.deleteBaseMenuPermission(permissionId);
    }


}
