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.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.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);
    }


}
