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.RoleDataScopeDto;
import com.auth.model.base.vo.RoleDataScopeVo;
import com.auth.dao.base.entity.RoleDataScopeEntity;
import com.auth.service.base.service.RoleDataScopeService;
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/role-data-scope")
@RequiredArgsConstructor
public class RoleDataScopeController {

    private final RoleDataScopeService roleDataScopeService;

    @Operation(summary = "分页查询系统角色数据权限范围", description = "分页查询系统角色数据权限范围")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<RoleDataScopeVo>> getRoleDataScopePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            RoleDataScopeDto dto) {
        Page<RoleDataScopeEntity> pageParams = new Page<>(page, limit);
        PageResult<RoleDataScopeVo> pageResult = roleDataScopeService.getRoleDataScopePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据id查询系统角色数据权限范围详情", description = "根据id查询系统角色数据权限范围详情")
    @GetMapping("{id}")
    public Result<RoleDataScopeVo> getRoleDataScopeById(@PathVariable("id") Long id) {
        RoleDataScopeVo roleDataScopeVo = roleDataScopeService.getRoleDataScopeById(id);

        return Result.success(roleDataScopeVo);
    }

    @Operation(summary = "添加系统角色数据权限范围", description = "添加系统角色数据权限范围")
    @PostMapping()
    public Result<String> addRoleDataScope(@Valid @RequestBody RoleDataScopeDto dto) {
        roleDataScopeService.addRoleDataScope(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新系统角色数据权限范围", description = "更新系统角色数据权限范围")
    @PutMapping()
    public Result<String> updateRoleDataScope(@Valid @RequestBody RoleDataScopeDto dto) {
        roleDataScopeService.updateRoleDataScope(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除系统角色数据权限范围", description = "删除系统角色数据权限范围")
    @DeleteMapping()
    public Result<String> deleteRoleDataScope(@RequestBody List<Long> ids) {
        roleDataScopeService.deleteRoleDataScope(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}