import 'package:myhr_facescan/active_liveness/enum.dart';

class FaceGestureVerifier {
  isMatch(double panOrSmile, double tilt, EFaceGesture gesture) {
    var match = false;
    var isExpression = gesture == EFaceGesture.smile;

    if (isExpression) {
      // const double SMILE_CONF_LEVEL_LOW = 0.3;
      const double SMILE_CONF_LEVEL_HIGH = 0.8;

      if (panOrSmile > SMILE_CONF_LEVEL_HIGH && gesture == EFaceGesture.smile) {
        match = true;
      }
    } else {
      if (gesture == EFaceGesture.turnLeft ||
          gesture == EFaceGesture.turnRight ||
          gesture == EFaceGesture.lookStraight) {
        const double HOR_CONF_LEVEL_LOW = 2;
        const double HOR_CONF_LEVEL_HIGH = 17;

        if (panOrSmile.abs() > HOR_CONF_LEVEL_HIGH) {
          if (panOrSmile > 0 && gesture == EFaceGesture.turnLeft) {
            match = true;
          } else if (panOrSmile <= 0 && gesture == EFaceGesture.turnRight) {
            match = true;
          }
        } else if (panOrSmile.abs() < HOR_CONF_LEVEL_LOW &&
            gesture == EFaceGesture.lookStraight) {
          match = true;
        }
      } else {
        // const double UP_CONF_LEVEL_LOW = 2;
        const double UP_CONF_LEVEL_HIGH = 6;
        // const double DOWN_CONF_LEVEL_LOW = -2;
        const double DOWN_CONF_LEVEL_HIGH = -3;

        if (tilt > UP_CONF_LEVEL_HIGH && gesture == EFaceGesture.lookUp) {
          match = true;
        } else if (tilt < DOWN_CONF_LEVEL_HIGH &&
            gesture == EFaceGesture.lookDown) {
          match = true;
        }
      }
    }

    return match;
  }
}
