package com.xunmei.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunmei.common.core.web.domain.AjaxResult;
import com.xunmei.system.api.model.LoginUser;
import com.xunmei.system.domain.vo.AppType;
import com.xunmei.system.service.IMenuService;
import org.springframework.web.bind.annotation.*;
import com.xunmei.system.domain.SysMenu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.xunmei.common.core.web.domain.AjaxResult.success;
import static com.xunmei.common.core.web.domain.AjaxResult.error;
import javax.annotation.Resource;
import com.xunmei.common.security.annotation.RequiresPermissions;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * <p>
 * SysMenuController 前端控制器
 * </p>
 *
 * @author luojun
 * @since 2023-08-04
 */
@Api(tags = {"SysMenuController"})
@RestController
@RequestMapping("/SysMenu")
public class MenuController {

    private Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private IMenuService sysMenuService;


    @ApiOperation(value = "按组列表")
    @GetMapping(value = {"/group/list/{appType}", "/group/list"})
    AjaxResult groupList(@PathVariable(required = false) AppType appType) {

        List<Object> result = null;
        return success(result);
        //}
    }


    @ApiOperation(value = "新增菜单权限表")
    @RequiresPermissions("system:SysMenu:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysMenu sysMenu){
        try {
            return sysMenuService.add(sysMenu);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "删除菜单权限表")
    @RequiresPermissions("system:SysMenu:delete")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            return sysMenuService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "更新菜单权限表")
    @RequiresPermissions("system:SysMenu:update")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody SysMenu sysMenu){
        try {
            return sysMenuService.updateData(sysMenu);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "查询菜单权限表分页数据")
    @RequiresPermissions("system:SysMenu:findByPage")
    @GetMapping("/findByPage")
    public AjaxResult findListByPage(Page<SysMenu> page, SysMenu sysMenu){
        try {
            return sysMenuService.findListByPage(page, sysMenu);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "id查询菜单权限表")
    @RequiresPermissions("system:SysMenu:findById")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Long id){
        try {
            return sysMenuService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

}
