<?php

namespace App\Http\Services\V1_1;

use App\Generated\V1_1\Messages\Common\FaceDetectMessage;
use App\Services\Vendor\BaiduAi\FaceService;

class CommonService
{
    public function faceDetect(FaceDetectMessage $message)
    {
        $images = $message->getImage();

        $fs = new FaceService();
        $data = $fs->detect($images, 'URL', array(
            'face_field' => "quality",
            'max_face_num' => 1,
            'face_type' => 'LIVE'
        ));

        $message->setResponse([
            'detect' => $data['error_code'] == 0 && $data['result']['face_num'] > 0
                && $data['result']['face_list'][0]['quality']['occlusion']['left_eye'] < 0.6
                && $data['result']['face_list'][0]['quality']['occlusion']['right_eye'] < 0.6
                && $data['result']['face_list'][0]['quality']['occlusion']['nose'] < 0.7
                && $data['result']['face_list'][0]['quality']['occlusion']['mouth'] < 0.7
                && $data['result']['face_list'][0]['quality']['occlusion']['left_cheek'] < 0.8
                && $data['result']['face_list'][0]['quality']['occlusion']['right_cheek'] < 0.8
                && $data['result']['face_list'][0]['quality']['occlusion']['chin_contour'] < 0.8
                && $data['result']['face_list'][0]['quality']['blur'] < 0.7
                && $data['result']['face_list'][0]['quality']['illumination'] > 40
        ]);
    }
}
