package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.ExtractFingerPrintRequest;
import com.aliyun.facebody20191230.models.ExtractFingerPrintResponse;
import com.aliyun.facebody20191230.models.ExtractFingerPrintResponseBody;
import com.heyu.api.alibaba.handle.facebody.AExtractFingerPrintHandle;
import com.heyu.api.alibaba.request.facebody.AExtractFingerPrintRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.request.face.EnhanceFaceReq;
import com.heyu.api.request.face.ExtractFingerPrintReq;
import com.heyu.api.resp.face.ExtractFingerPrintResp;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * https://next.api.aliyun.com/api/facebody/2019-12-30/ExtractFingerPrint?tab=DOC&lang=JAVA&RegionId=cn-shanghai
 *
 * 指纹提取
 *
 * ExtractFingerPrint
 */
@Slf4j
@RestController
@RequestMapping("/finger")
@NotIntercept
public class ExtractFingerPrintController extends BaseController {

    @Autowired
    private AExtractFingerPrintHandle aExtractFingerPrintHandle;


    @RequestMapping("/print")
    @CacheResult
    public R print(ExtractFingerPrintReq req) {
        ExtractFingerPrintResp resp = new ExtractFingerPrintResp();

        AExtractFingerPrintRequest aExtractFingerPrintRequest = new AExtractFingerPrintRequest();
        aExtractFingerPrintRequest.setImageBase64(req.getImageBase64());
        aExtractFingerPrintRequest.setImageUrl(req.getImageUrl());
        ApiR<ExtractFingerPrintResponse> aR = aExtractFingerPrintHandle.handle(aExtractFingerPrintRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            ExtractFingerPrintResponseBody.ExtractFingerPrintResponseBodyData bodyData = aR.getData().getBody().getData();
            resp.setFingerPrintBase64(bodyData.getFingerPrint());
            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }

}
