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;
import java.util.Map;

import static org.jeecg.modules.app.ezt.GetEidToken.getEidResult;
import static org.jeecg.modules.app.ezt.GetEidToken.getEidToken;

@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,
                                          @RequestParam(required = false) @Schema(description = "手机号") String phone){
        return Result.ok(userService.updateUserInfo(nickName,avatarUrl,phone));
    }

    /**
     * @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());
    }

    /**
     * @Author SheepHy
     * @Description 人脸识别
     * @Date 15:58 2025/8/25
     **/
    @GetMapping("/faceRecognition")
    @Operation(summary = "人脸识别")
    public Result<String> faceRecognition(@RequestParam("idCard") @Schema(description = "身份证") String idCard,
                                          @RequestParam("name") @Schema(description = "姓名")String name) throws Exception {
        return Result.ok(getEidToken(idCard,name));
    }

    /**
     * <p>获取E证通结果信息</p>
     * @author SheepHy
     * @param eidToken，参数为类则包含{@link Object}
     * @return 返回值描述，如无返回值则为void 返回值为类则包含{@link String}
     */
    @GetMapping("/getEidResult")
    @Operation(summary = "获取E证通结果信息")
    public Result<Map<String,String>> getEidResultBy(@RequestParam("eidToken") String eidToken){
        return Result.OK(getEidResult(eidToken));
    }

//    /**
//     * @Author SheepHy
//     * @Description 分页查询开门记录
//     * @Date 10:53 2025/8/25
//     **/
//    @Operation(summary="分页查询开门记录")
//    @GetMapping(value = "/listOpenDoor")
//    public Result<String> listOpenDoor(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws IOException, InterruptedException {
//        return Result.OK(queryOpenDoorRecord(pageNo, pageSize));
//    }
}
