package com.ycwl.basic.controller.mobile;

import com.ycwl.basic.model.jwt.JwtInfo;
import com.ycwl.basic.model.mobile.face.FaceRecognizeResp;
import com.ycwl.basic.model.mobile.scenic.content.ContentPageVO;
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
import com.ycwl.basic.service.pc.FaceService;
import com.ycwl.basic.utils.ApiResponse;
import com.ycwl.basic.utils.JwtTokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/4 17:03
 */
@RestController
@RequestMapping("/api/mobile/face/v1")
@Api(tags = "用户人脸相关接口")
public class
AppFaceController {

    @Autowired
    private FaceService faceService;

    /**
     * 1、上传人脸照片
     * 2、人脸照片有效性校验
     * 3、校验失败，删除，提示重新上传
     * 4、校验成功，保存用户人脸信息，将访问人脸照片访问地址响应给前端
     * @param file
     * @param scenicId
     * @return
     */
    @ApiOperation("人脸照片上传")
    @PostMapping("/faceUPload")
    public ApiResponse<FaceRecognizeResp> faceUpload(@RequestParam("file")MultipartFile file, @RequestParam("scenicId") Long scenicId) {
        //获取用户id
        JwtInfo worker = JwtTokenUtil.getWorker();
        Long userId = worker.getUserId();
        FaceRecognizeResp resp = faceService.faceUpload(file, scenicId, userId);
        return ApiResponse.success(resp);
    }

    @GetMapping("/scenic/{scenicId}/list")
    public ApiResponse<List<FaceRespVO>> list(@PathVariable("scenicId") String scenicId) {
        JwtInfo worker = JwtTokenUtil.getWorker();
        Long userId = worker.getUserId();
        List<FaceRespVO> list = faceService.listByUser(userId, scenicId);
        return ApiResponse.success(list);
    }

    @GetMapping("/{faceId}")
    public ApiResponse<FaceRespVO> getById(@PathVariable("faceId") Long faceId) {
        return faceService.getById(faceId);
    }

    @DeleteMapping("/{faceId}")
    public ApiResponse<String> deleteFace(@PathVariable("faceId") Long faceId) {
        return faceService.deleteFace(faceId);
    }

    @PostMapping("/{faceId}/match")
    public ApiResponse<String> match(@PathVariable("faceId") Long faceId) {
        faceService.matchFaceId(faceId);
        return ApiResponse.success("");
    }


    @ApiOperation("景区视频源素材列表")
    @GetMapping("/{faceId}/contentList")
    public ApiResponse<List<ContentPageVO>> contentList(@PathVariable Long faceId) {
        List<ContentPageVO> contentPageVOS = faceService.faceContentList(faceId);
        return  ApiResponse.success(contentPageVOS);
    }
}
