package com.njzscloud.dispose.sys.menu.controller;

import cn.hutool.core.lang.Assert;
import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.sys.menu.pojo.param.MenuAddParam;
import com.njzscloud.dispose.sys.menu.pojo.param.MenuModifyParam;
import com.njzscloud.dispose.sys.menu.pojo.param.MenuSearchParam;
import com.njzscloud.dispose.sys.menu.pojo.result.MenuDetailResult;
import com.njzscloud.dispose.sys.menu.service.MenuService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单
 */
@Slf4j
@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
public class MenuController {

    private final MenuService menuService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<Long> add(@RequestBody @Validated MenuAddParam menuAddParam) {
        return R.success(menuService.add(menuAddParam));
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody @Validated MenuModifyParam menuModifyParam) {
        menuService.modify(menuModifyParam);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        Assert.notEmpty(ids, "未指定要删除的数据");
        menuService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<MenuDetailResult> detail(@RequestParam("id") Long id) {
        return R.success(menuService.detail(id));
    }

    /**
     * 查询所有
     */
    @GetMapping("/list_all")
    public R<List<MenuDetailResult>> listAll(MenuSearchParam menuSearchParam) {
        return R.success(menuService.listAll(menuSearchParam));
    }


    /**
     * 分页查询
     */
    @GetMapping("/page_list")
    public R<PageResult<MenuDetailResult>> paging(PageParam pageParam, MenuSearchParam menuSearchParam) {
        return R.success(menuService.paging(pageParam, menuSearchParam));
    }


}
