package com.github.microservice.auth.server.core.controller.user;

import com.github.microservice.auth.client.content.ResultContent;
import com.github.microservice.auth.client.model.UserFaceUploadModel;
import com.github.microservice.auth.client.service.UserService;
import com.github.microservice.auth.server.core.service.local.UserFaceServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserFaceServiceImpl userFaceService;

    @Operation(summary = "刷新令牌", description = "刷新用户访问令牌")
    @RequestMapping(value = "refreshToken", method = {RequestMethod.GET, RequestMethod.POST})
    public Object refreshToken(@Parameter(name = "refreshToken", description = "刷新令牌", example = "ShkUxSATO2SNrQ7CLixCHTwA354") @RequestParam("refreshToken") String refreshToken) {
        return this.userService.refreshToken(refreshToken);
    }

    @Operation(summary = "上传人脸", description = "上传人脸")
    @RequestMapping(value = "uploadFace", method = {RequestMethod.POST})
    public ResultContent<String> upload(UserFaceUploadModel userFaceUploadModel){
        return userFaceService.upload(userFaceUploadModel);
    }

    @Operation(summary = "比对人脸", description = "比对人脸")
    @RequestMapping(value = "matchesFace", method = {RequestMethod.POST})
    public ResultContent<Object> matchesFace(@RequestParam("file") MultipartFile file){
        return userFaceService.matches(file);
    }

    @Operation(summary = "删除人脸", description = "删除人脸")
    @RequestMapping(value = "deleteFace", method = {RequestMethod.GET})
    public ResultContent deleteFace(@RequestParam("userId") String userId, @RequestParam("faceFileId") String faceFileId){
        return userFaceService.delete(userId, faceFileId);
    }
}
