package com.seer.teach.user.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.user.admin.request.*;
import com.seer.teach.user.admin.response.AdminUserInfoResp;
import com.seer.teach.user.admin.response.AdminUserPageResp;
import com.seer.teach.user.admin.service.AdminAuthorityService;
import com.seer.teach.user.admin.service.AdminUserService;
import com.seer.teach.user.service.IUserRoleService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 用户角色前端控制器
 * </p>
 *
 * @author Captain
 * @since 2025-05-14
 */
@RestController
@RequestMapping("/user/role")
@Tag(name = "管理端 - 用户角色")
@Validated
@RequiredArgsConstructor
public class AdminUserRoleController {

    private final IUserRoleService userRoleService;

    @PostMapping("/alloc")
    @LogPrint
    @SaCheckLogin(type = StpUtil.TYPE)
    @Operation(summary = "分配角色")
    @SaCheckPermission("admin:user:role:alloc")
    public ResultBean<Boolean> allocUserRole(@RequestBody @Validated AllocRoleReq allocRoleReq) {
        return ResultBean.success(userRoleService.allocUserRole(allocRoleReq.getUserId(), allocRoleReq.getRoleIds()));
    }

    @PostMapping("/delete")
    @LogPrint
    @SaCheckLogin(type = StpUtil.TYPE)
    @Operation(summary = "取消角色")
    @SaCheckPermission("admin:user:delete")
    public ResultBean<Boolean> list(@RequestBody AllocRoleReq allocRoleReq){
        return ResultBean.success(userRoleService.deleteUserRole(allocRoleReq.getUserId(), allocRoleReq.getRoleIds()));
    }
}