package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.MonitorExaminationResponse;
import com.aliyun.facebody20191230.models.MonitorExaminationResponseBody;
import com.heyu.api.alibaba.handle.facebody.AMonitorExaminationHandle;
import com.heyu.api.alibaba.request.facebody.AMonitorExaminationRequest;
import com.heyu.api.controller.BaseController;
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.MonitorExaminationScreenReq;
import com.heyu.api.resp.face.MonitorExaminationScreenResp;
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/MonitorExamination?tab=DOC&params={%22ImageURL%22:%22http%3A%2F%2Fworkbench-file-transfer.oss-cn-shanghai.aliyuncs.com%2Fuser-files%2F84753ea9-9809-4348-ac27-71437b89fee9-WechatIMG29.jpg%3FOSSAccessKeyId%3DLTAI5tRvL6vYdjKSfTFZ156m%26Expires%3D1742056256%26Signature%3Dl%252B1vglgYe%252BIN3wHE4Eror6e5tj4%253D%26response-content-disposition%3Dattachment%22,%22Type%22:1}&lang=JAVA
 *线上监考
 *
 * MonitorExamination
 *
 * 监控屏幕
 *
 */
@Slf4j
@RestController
@RequestMapping("/monitor")
@NotIntercept
public class MonitorExaminationScreenController extends BaseController {


    @Autowired
    private AMonitorExaminationHandle aMonitorExaminationHandle;

    @RequestMapping("/screen")
    public R screen(MonitorExaminationScreenReq req) {


        MonitorExaminationScreenResp monitorExaminationScreenResp = new MonitorExaminationScreenResp();

        AMonitorExaminationRequest aMonitorExaminationRequest = new AMonitorExaminationRequest();
        aMonitorExaminationRequest.setImageUrl(req.getImageUrl());
        aMonitorExaminationRequest.setImageBase64(req.getImageBase64());
        // 0：屏幕聊天工具检测
        aMonitorExaminationRequest.setType(0L);
        ApiR<MonitorExaminationResponse> aR = aMonitorExaminationHandle.handle(aMonitorExaminationRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            /***
             *
             {
             "RequestId": "A104C55A-BA6A-5FB6-B841-8DB5C11D2EA4",
             "Data": {
             "ChatScore": 1,
             "Threshold": 0.5
             }
             }
             */
            MonitorExaminationResponseBody.MonitorExaminationResponseBodyData responseBodyData = aR.getData().getBody().getData();
            monitorExaminationScreenResp.setChatScore(responseBodyData.getChatScore());
            monitorExaminationScreenResp.setThreshold(responseBodyData.getThreshold());
            return R.error().setData(monitorExaminationScreenResp);
        }
        return R.error();
    }


}
