package com.uniubi.Register;

public class UfaceRegister {
    private long handle;

    public enum Status{
        AUTH_INVALID_PASSWORD(-9, "AUTH_INVALID_PASSWORD"),         // 授权验证账号用户名或者密码错误
        AUTH_RESPONSE_PARSE_FAIL(-8,"AUTH_RESPONSE_PARSE_FAIL"),    // 远程返回内容解析失败
        AUTH_WRITE_NO_PERMISSION(-7,"AUTH_WRITE_NO_PERMISSION"),    // lic文件保存失败（设定路径无写入权限）
        AUTH_INFO_COMPARE_FAIL(-6,"AUTH_INFO_COMPARE_FAIL"),        // 硬件信息比对失败（lic文件直接拷贝至其他设备使用）
        AUTH_LACK_OF_TIMES(-5,"AUTH_LACK_OF_TIMES"),                // 授权申请次数已用尽
        AUTH_GET_INFO_FAIL(-4,"AUTH_GET_INFO_FAIL"),                // 获取本地硬件信息失败
        INIT_FAILED(-3,"INIT_FAILED"),                              // 初始化失败
        IMAGE_EMPTY(-2,"IMAGE_EMPTY"),                              // 图片为空
        IMAGE_DECODE_FAILED(-1,"IMAGE_DECODE_FAILED"),              // 图片解码失败
        SUCCESS (0,"SUCCESS"),                                      // 成功

        NO_FACE_DETECTED(1,"NO_FACE_DETECTED"),                     // 未检测到面部
        FACE_BOX_MULTIPLE(2,"FACE_BOX_MULTIPLE"),                   // 有多个面部
        FACE_BOX_TOO_SMALL(3,"FACE_BOX_TOO_SMALL"),                 // 面部过小
        FACE_BOX_OUT_OF_RANGE(4,"FACE_BOX_OUT_OF_RANGE"),           // 面部越界
        FACE_PITCH_INVALID(5,"FACE_PITCH_INVALID") ,                // 面部俯仰角（上下点头）过大
        FACE_YAW_INVALID(6,"FACE_YAW_INVALID"),                     // 面部偏航角（左右转头）过大
        FACE_ROLL_INVALID(7,"FACE_ROLL_INVALID"),                   // 面部翻滚角（左右歪头）过大
        FACE_TOO_BRIGHT(8,"FACE_TOO_BRIGHT"),                       // 面部亮度过亮
        FACE_TOO_DARK(9,"FACE_TOO_DARK"),                           // 面部亮度过暗
        FACE_TOO_BLUR (10,"FACE_TOO_BLUR"),                         // 面部模糊
        FACE_ILLUMINATION_UNEVEN(11,"FACE_ILLUMINATION_UNEVEN"),    // 面部光照不均匀
        FACE_ORIENTATION_INVALID(12,"FACE_ORIENTATION_INVALID"),    // 面部朝向不对
        FACE_CLASS_INVALID(13,"FACE_CLASS_INVALID"),                // 非正常面部
        FACE_IS_COVER(14,"FACE_IS_COVER"),                          // 面部被遮挡
        FACE_ALMIGHTY_FACE(15,"FACE_ALMIGHTY_FACE"),                // 万能人脸
        INPUT_INVALID_BOX(16,"INPUT_INVALID_BOX"),                  // 输入框无效
        LOAD_MODEL_FAILED(17,"LOAD_MODEL_FAILED"),                  // 加载模型失败
        CONFIG_FILE_INVALID(18,"CONFIG_FILE_INVALID"),              // 配置文件无效
        ;

        private Integer code;
        private String message;

        Status(Integer code, String message) {
            this.code = code;
            this.message = message;
        }

        public Integer getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }


    public static int Auth(String userName, String password, String license) {

        return UfaceRegisterJNI.Auth(userName, password, license);
    }

    public static String GetSDKVersion() {
        return UfaceRegisterJNI.GetSDKVersion();
    }

    public static void SetLogMode(int log_mode) {
        UfaceRegisterJNI.SetLogMode(log_mode);
    }

    public static void SetModelPath(String model_path) {
        UfaceRegisterJNI.SetModelPath(model_path);
    }

    public UfaceRegister() {
        handle = UfaceRegisterJNI.NewRegister();
    }

    public void release() {
        if (handle == 0) {
            return;
        }
        UfaceRegisterJNI.ReleaseRegister(handle);
        handle = 0;
    }


    public int JudgeImage(byte[] image_data, FaceBox box) {
        if (handle == 0) {
            return -1;
        }
        return UfaceRegisterJNI.JudgeImage(handle, image_data, box) ;

    }

    public byte[] GetSimpleImage(byte[] image_data, FaceBox box,int resize_mode,int save_size) {
        if (handle == 0) {
            return null;
        }
        return UfaceRegisterJNI.GetSimpleImage(handle, image_data, box,resize_mode,save_size);
    }

    public String GetFeature(byte[] image_data, int feature_version, FaceBox box) {
        if (handle == 0) {
            return null;
        }

        return UfaceRegisterJNI.GetFeature(handle, image_data, feature_version, box);

    }
    public float DynamicQuality(byte[] image_data, FaceBox box) {
        if (handle == 0) {
            return -1;
        }
        return UfaceRegisterJNI.DynamicQuality(handle, image_data, box) ;

    }
    public float CompareFeat(String featA,String featB){
        if (handle == 0) {
            return -1;
        }
        return UfaceRegisterJNI.CompareFeat(handle,featA,featB);
    }
}
