package cn.iocoder.byzs.module.web.controller.admin.user;

import cn.iocoder.byzs.framework.common.pojo.CommonResult;
import cn.iocoder.byzs.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.byzs.module.web.controller.admin.user.vo.WebUserVO;
import cn.iocoder.byzs.module.web.service.user.WebUserInfoServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.byzs.framework.common.pojo.CommonResult.error;
import static cn.iocoder.byzs.framework.common.pojo.CommonResult.success;

@Tag(name = "前端")
@RestController
@RequestMapping("/bjdxWeb/web")
public class WebUserInfoController {

    @Resource
    private WebUserInfoServiceImpl userInfoServiceImpl;

    @PostMapping("/activateInviteCode")
    @Operation(summary = "激活邀请码")
    public CommonResult<Boolean> activateInviteCode(String inviteCode) {
        return success(userInfoServiceImpl.activateInviteCode(inviteCode));
    }

    @GetMapping("/getUserInfo")
    @Operation(summary = "获取用户信息")
    public CommonResult<WebUserVO> getUserInfo(Long userId) {
        if(userId == null){
            return error(null,"用户ID不能为空");
        }
        if(!userId.equals(WebFrameworkUtils.getLoginUserId())){
            return error(null,"您没有权限查询其他用户信息");
        }

        return success(userInfoServiceImpl.getUserInfo(userId));
    }

}
