package com.zhongshu.card.server.core.controller.user;

import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.ProjectOidParam;
import com.zhongshu.card.client.model.forgotPassword.ForgotPasswordParam;
import com.zhongshu.card.client.model.forgotPassword.ValidateUserModel;
import com.zhongshu.card.client.model.forgotPassword.ValidateUserParam;
import com.zhongshu.card.server.core.service.user.ForgotPassWordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 *
 * @author TRX
 * @date 2025/3/26
 */
@RestController
@RequestMapping("forgotPassWord")
@Tag(name = "找回密码")
public class ForgotPassWordController {

    @Autowired
    private ForgotPassWordService forgotPassWordService;

    @Operation(summary = "验证用户（通过电话号码和身份证）", description = "验证用户")
    @RequestMapping(value = {"verifyUserExitByPhone"}, method = {RequestMethod.POST})
    public ResultContent<ValidateUserModel> verifyUserExitByPhone(@RequestBody ValidateUserParam param) {
        return forgotPassWordService.verifyUserExitByPhone(param);
    }

    @RequestMapping(value = "verifyUserExitByImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, method = RequestMethod.POST)
    @Operation(summary = "用人脸图片判断用户是否存在", description = "用人脸图片判断用户是否存在")
    public ResultContent verifyUserExitByImage(
            HttpServletRequest request, HttpServletResponse response,
            @RequestPart("file") MultipartFile file, ProjectOidParam param) throws IOException {
        if (file == null || file.isEmpty()) {
            return ResultContent.buildFail("文件不能为空");
        }
        return forgotPassWordService.verifyUserExitByImage(file);
    }

    @Operation(summary = "重置密码", description = "验证用户")
    @RequestMapping(value = {"resetPassword"}, method = {RequestMethod.POST})
    public ResultContent resetPassword(@RequestBody ForgotPasswordParam param) {
        return forgotPassWordService.resetPassword(param);
    }

}
