package com.ycwl.basic.controller.pc;
import com.ycwl.basic.integration.kafka.service.FaceProcessingKafkaService;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity;
import com.ycwl.basic.model.pc.faceSample.req.FaceSampleReqQuery;
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
import com.ycwl.basic.service.pc.FaceSampleService;
import com.ycwl.basic.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/2 16:33
 */
@RestController
@RequestMapping("/api/faceSample/v1")
// 人脸样本管理
public class FaceSampleController {
    @Autowired
    private FaceSampleService FaceSampleService;
    @Autowired(required = false)
    private FaceProcessingKafkaService faceProcessingKafkaService;

    // 分页查询人脸样本
    @PostMapping("/page")
    public ApiResponse<PageInfo<FaceSampleRespVO>> pageQuery(@RequestBody FaceSampleReqQuery FaceSampleReqQuery) {
        return FaceSampleService.pageQuery(FaceSampleReqQuery);
    }
    // 人脸样本列表查询
    @PostMapping("/list")
    public ApiResponse<List<FaceSampleRespVO>> list(@RequestBody FaceSampleReqQuery FaceSampleReqQuery) {
        return FaceSampleService.list(FaceSampleReqQuery);
    }
    // 人脸样本详情查询
    @GetMapping("/getDetail/{id}")
    public ApiResponse<FaceSampleRespVO> getDetail(@PathVariable("id") Long id) {
        return FaceSampleService.getById(id);
    }

    /**
     * 重试失败的人脸识别
     * 用于手动重试状态为-1的人脸样本
     *
     * @param id 人脸样本ID
     * @return 重试结果
     */
    @PostMapping("/retry/{id}")
    public ApiResponse<String> retryFaceRecognition(@PathVariable("id") Long id) {
        if (faceProcessingKafkaService == null) {
            return ApiResponse.fail("Kafka服务未启用,无法重试人脸识别");
        }
        
        boolean success = faceProcessingKafkaService.retryFaceRecognition(id);
        if (success) {
            return ApiResponse.success("人脸识别重试任务已提交");
        } else {
            return ApiResponse.fail("提交重试任务失败,请检查人脸样本状态");
        }
    }

}
