package org.xyzh.system.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.xyzh.api.system.menu.MenuService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.menu.TbSysMenu;
import org.xyzh.common.dto.menu.TbSysMenuPermission;

@RestController
@RequestMapping("/menus")
public class MenuController {
    private static final Logger logger = LoggerFactory.getLogger(MenuController.class);


    @Autowired
    private MenuService menuService;

    /**
     * @description    查询所有菜单
     * @return    ResultDomain<TbSysMenu> 菜单列表
     * @author    yslg
     * @since 2025-10-06
     */
    @PostMapping("/all")
    public ResultDomain<TbSysMenu> getAllMenus() {
        return menuService.getAllMenus();
    }

    /**
     * @description    查询菜单
     * @param    filter 过滤条件
     * @return    ResultDomain<TbSysMenu> 菜单列表
     * @author    yslg
     * @since 2025-10-06
     */
    @PostMapping("/list")
    public ResultDomain<TbSysMenu> getMenuList(@RequestBody TbSysMenu filter) {
        return menuService.getMenuList(filter);
    }

    /**
     * @description    查询菜单
     * @param    menuId 菜单ID
     * @return    ResultDomain<TbSysMenu> 菜单信息
     * @author    yslg
     * @since 2025-10-06
     */
    @PostMapping("/id")
    public ResultDomain<TbSysMenu> getMenuById(@RequestBody String menuId) {
        return menuService.getMenuById(menuId);
    }

    /**
     * @description    创建菜单
     * @param    menu 菜单信息
     * @return    ResultDomain<TbSysMenu> 菜单信息
     * @author    yslg
     * @since 2025-10-06
     */
    @PostMapping("/menu")
    public ResultDomain<TbSysMenu> createMenu(@RequestBody TbSysMenu menu) {
        return menuService.createMenu(menu);
    }

    /**
     * @description    删除菜单
     * @param    menuId 菜单ID
     * @return    ResultDomain<TbSysMenu> 菜单信息
     * @author    yslg
     * @since 2025-10-06
     */
    @DeleteMapping("/menu")
    public ResultDomain<TbSysMenu> deleteMenu(@RequestBody String menuId) {
        return menuService.deleteMenu(menuId);
    }

    /**
     * @description    更新菜单
     * @param    menu 菜单信息
     * @return    ResultDomain<TbSysMenu> 菜单信息
     * @author    yslg
     * @since 2025-10-06
     */
    @PutMapping("/menu")
    public ResultDomain<TbSysMenu> updateMenu(@RequestBody TbSysMenu menu) {
        return menuService.updateMenu(menu);
    }
    

    /**
     * @description    查询菜单权限
     * @param    menuId 菜单ID
     * @return    ResultDomain<TbSysMenuPermission> 菜单权限信息
     * @author    yslg
     * @since 2025-10-06
     */
    @PostMapping("/permission")
    public ResultDomain<TbSysMenuPermission> getMenuPermission(@RequestBody TbSysMenu menu) {
        return menuService.getMenuPermission(menu.getMenuID());
    }
    
}
