package com.auth.service.base.controller;

import com.auth.common.model.common.result.PageResult;
import com.auth.common.model.common.result.Result;
import com.auth.common.model.common.result.ResultCodeEnum;
import com.auth.model.base.dto.MenuRoleDto;
import com.auth.model.base.vo.MenuRoleVo;
import com.auth.dao.base.entity.MenuRoleEntity;
import com.auth.service.base.service.MenuRoleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统菜单角色关联 前端控制器
 * </p>
 *
 * @author AuthoritySystem
 * @since 2025-07-17 23:06:38
 */
@Tag(name = "系统菜单角色关联", description = "系统菜单角色关联相关接口")
@RestController
@RequestMapping("/api/v1/base/menu-role")
@RequiredArgsConstructor
public class MenuRoleController {

    private final MenuRoleService menuRoleService;

    @Operation(summary = "分页查询系统菜单角色关联", description = "分页查询系统菜单角色关联")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<MenuRoleVo>> getMenuRolePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            MenuRoleDto dto) {
        Page<MenuRoleEntity> pageParams = new Page<>(page, limit);
        PageResult<MenuRoleVo> pageResult = menuRoleService.getMenuRolePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据id查询系统菜单角色关联详情", description = "根据id查询系统菜单角色关联详情")
    @GetMapping("{id}")
    public Result<MenuRoleVo> getMenuRoleById(@PathVariable("id") Long id) {
        MenuRoleVo menuRoleVo = menuRoleService.getMenuRoleById(id);

        return Result.success(menuRoleVo);
    }

    @Operation(summary = "添加系统菜单角色关联", description = "添加系统菜单角色关联")
    @PostMapping()
    public Result<String> addMenuRole(@Valid @RequestBody MenuRoleDto dto) {
        menuRoleService.addMenuRole(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新系统菜单角色关联", description = "更新系统菜单角色关联")
    @PutMapping()
    public Result<String> updateMenuRole(@Valid @RequestBody MenuRoleDto dto) {
        menuRoleService.updateMenuRole(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除系统菜单角色关联", description = "删除系统菜单角色关联")
    @DeleteMapping()
    public Result<String> deleteMenuRole(@RequestBody List<Long> ids) {
        menuRoleService.deleteMenuRole(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}