package org.jeecg.modules.app.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.app.service.IUserService;
import org.jeecg.modules.app.vo.LoginUserVO;
import org.jeecg.modules.system.app.entity.AppKongfuZone;
import org.jeecg.modules.system.app.service.IAppKongfuZoneService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Tag(name = "App用户相关接口")
@RestController
@RequestMapping("/app/user")
public class AppUserController {
    @Resource
    private IUserService userService;

    @Resource
    private IAppKongfuZoneService appKongfuZoneService;

    /**
     * 登录
     *
     * @param code
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/loginByCode")
    @Operation(summary = "微信小程序登录接口")
    public Result<LoginUserVO> wechatLogin(@RequestParam @Schema(description = "微信登录返回的code") String code){
        return Result.ok(userService.wechatLogin(code));
    }

    /**
     * @Author SheepHy
     * @Description 修改用户基础信息
     * @Date 16:25 2025/7/18
     * @Param
     * @return
     **/
    @GetMapping("/updateUserInfo")
    @Operation(summary = "修改用户基础信息")
    public Result<Boolean> updateUserInfo(@RequestParam(required = false) @Schema(description = "用户昵称") String nickName,
                                          @RequestParam(required = false) @Schema(description = "用户头像") String avatarUrl){
        return Result.ok(userService.updateUserInfo(nickName,avatarUrl));
    }

    /**
     * @Author SheepHy
     * @Description 查询用户基础信息
     * @Date 16:48 2025/7/18
     * @Param
     * @return
     *
     **/
    @GetMapping("/getUserInfo")
    @Operation(summary = "查询用户基础信息")
    public Result<LoginUserVO> getUserInfo(){
        return Result.ok(userService.getUserInfo());
    }


    /**
     * @Author SheepHy
     * @Description 根据用户权限获取对应金刚区
     * @Date 13:56 2025/8/13
     **/
    @GetMapping("/queryKongfuZone")
    @Operation(summary = "根据用户权限获取对应金刚区")
    public Result<List<AppKongfuZone>> queryKongfuZone(){
        return Result.ok(appKongfuZoneService.queryKongfuZone());
    }
}
