package org.dromara.system.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.GameEventMenuVo;
import org.dromara.system.domain.bo.GameEventMenuBo;
import org.dromara.system.service.IGameEventMenuService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 基础菜单
 *
 * @author zlt
 * @date 2025-08-01
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameEventMenu")
public class GameEventMenuController extends BaseController {

    private final IGameEventMenuService gameEventMenuService;

    /**
     * 查询基础菜单列表
     */
    @SaCheckPermission("system:gameEventMenu:list")
    @GetMapping("/list")
    public TableDataInfo<GameEventMenuVo> list(GameEventMenuBo bo, PageQuery pageQuery) {
        return gameEventMenuService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出基础菜单列表
     */
    @SaCheckPermission("system:gameEventMenu:export")
    @Log(title = "基础菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameEventMenuBo bo, HttpServletResponse response) {
        List<GameEventMenuVo> list = gameEventMenuService.queryList(bo);
        ExcelUtil.exportExcel(list, "基础菜单", GameEventMenuVo.class, response);
    }

    /**
     * 获取基础菜单详细信息
     *
     * @param menuId 主键
     */
    @SaCheckPermission("system:gameEventMenu:query")
    @GetMapping("/{menuId}")
    public R<GameEventMenuVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long menuId) {
        return R.ok(gameEventMenuService.queryById(menuId));
    }

    /**
     * 新增基础菜单
     */
    @SaCheckPermission("system:gameEventMenu:add")
    @Log(title = "基础菜单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GameEventMenuBo bo) {
        return toAjax(gameEventMenuService.insertByBo(bo));
    }

    /**
     * 修改基础菜单
     */
    @SaCheckPermission("system:gameEventMenu:edit")
    @Log(title = "基础菜单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GameEventMenuBo bo) {
        return toAjax(gameEventMenuService.updateByBo(bo));
    }

    /**
     * 删除基础菜单
     *
     * @param menuIds 主键串
     */
    @SaCheckPermission("system:gameEventMenu:remove")
    @Log(title = "基础菜单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] menuIds) {
        return toAjax(gameEventMenuService.deleteWithValidByIds(List.of(menuIds), true));
    }
}
