<?php
/**
 * @package embed-sharepoint-onedrive-documents
 * @author miniOrange
 * @link https://plugins.miniorange.com
 */


namespace MoSharePointObjectSync\LicenseLibrary\Utils;

use MoSharePointObjectSync\LicenseLibrary\Classes\Mo_AESEncryption;
use MoSharePointObjectSync\LicenseLibrary\Classes\Mo_License_Dao;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Grace_Expired_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Invalid_Expiry_Date_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Missing_Customer_Email_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Missing_License_Key_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Missing_Or_Invalid_Customer_Key_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Unknown_Error_Exception;
use MoSharePointObjectSync\LicenseLibrary\Classes\Mo_License_Constants;
use MoSharePointObjectSync\LicenseLibrary\Mo_License_Config;
use MoSharePointObjectSync\LicenseLibrary\Mo_License_Service;
if (defined("\x41\x42\x53\x50\x41\x54\x48")) {
    goto Xi;
}
exit;
Xi:
class Mo_License_Service_Utility
{
    public static function check_customer_login()
    {
        $w6 = Mo_License_Dao::mo_get_option(Mo_License_Config::CUSTOMER_EMAIL_OPTION);
        $jE = Mo_License_Dao::mo_get_option(Mo_License_Config::CUSTOMER_KEY_OPTION);
        if (!$w6) {
            goto nj;
        }
        if (!$jE || !is_numeric(trim($jE))) {
            goto eM;
        }
        goto un;
        nj:
        throw new Mo_License_Missing_Customer_Email_Exception();
        goto un;
        eM:
        throw new Mo_License_Missing_Or_Invalid_Customer_Key_Exception();
        un:
    }
    public static function check_customer_login_and_license()
    {
        self::check_customer_login();
        $VH = Mo_License_Dao::mo_get_option(Mo_License_Config::LICENSE_KEY_OPTION);
        if ($VH) {
            goto xX;
        }
        throw new Mo_License_Missing_License_Key_Exception();
        xX:
    }
    public static function is_license_grace_expired()
    {
        $EQ = self::mo_decrypt_data(Mo_License_Dao::mo_get_option(Mo_License_Constants::LICENSE_EXPIRY_DATE_OPTION));
        if ($EQ) {
            goto mI;
        }
        throw new Mo_License_Invalid_Expiry_Date_Exception();
        mI:
        try {
            $ML = gmdate("\131\x2d\155\x2d\x64", strtotime($EQ));
            $XH = strtotime("\53" . Mo_License_Config::GRACE_PERIOD_DAYS . "\40\x64\141\x79\x73", strtotime($EQ));
            $HQ = gmdate("\x59\x2d\x6d\x2d\144", $XH);
            $xN = new \DateTime();
            $xN = $xN->format("\131\x2d\155\x2d\x64");
        } catch (\Exception $FM) {
            throw new Mo_License_Unknown_Error_Exception();
        }
        if ($xN > $HQ) {
            goto Zu;
        }
        if ($xN > $ML) {
            goto C3;
        }
        goto Et;
        Zu:
        throw new Mo_License_Grace_Expired_Exception();
        goto Et;
        C3:
        return self::return_false_with_code("\x4c\111\103\x45\116\x53\105\137\111\116\137\107\122\x41\103\105");
        Et:
        return self::return_false_with_code("\114\111\x43\x45\x4e\x53\105\x5f\126\101\114\x49\x44");
    }
    public static function return_true_with_code($Cf)
    {
        return array("\x53\x54\101\124\x55\x53" => true, "\x43\117\x44\105" => $Cf);
    }
    public static function return_false_with_code($Cf)
    {
        return array("\x53\124\101\x54\x55\123" => false, "\x43\117\x44\x45" => $Cf);
    }
    public static function mo_decrypt_data($KY)
    {
        $cD = Mo_License_Dao::mo_get_option(Mo_License_Config::CUSTOMER_TOKEN_OPTION);
        $v8 = Mo_AESEncryption::decrypt_data($KY, $cD);
        return $v8;
    }
    public static function mo_encrypt_data($KY)
    {
        $cD = Mo_License_Dao::mo_get_option(Mo_License_Config::CUSTOMER_TOKEN_OPTION);
        $Gr = Mo_AESEncryption::encrypt_data($KY, $cD);
        return $Gr;
    }
}
