<?php
namespace Claromentis\People\Subscriber;

$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] ?: array()) + array("_2593d6ad580eddd65c8b5b7ffd12459" . "d" => base64_decode("RmFpbGVkIHRvIHNlbmQgbGljZW5zZSBsaW1pdCBub3RpZmljYXRpb24sIG" . "VtYWlsIGFkZHJlc3Mgc3VwcGxpZWQgZm9yIGxpY2Vuc2UncyByZXNwb25z" . "aWJsZSBwZXJzb24gZG9lcyBub3QgY29uZm9ybSB0byB0aGUgUkZDLTgyMi" . "BzdGFuZGFyZDog"), "_13626a711726e2df9aa25031d1" . "6575b6" => base64_decode("RmFpbGVkIHRvIHNlbmQgbGljZW5zZSBsaW1pdCBub3RpZmljYXRpb24sIGludmFsaWQgc3lzdGVtIGFkZHJlc3MgY29uZmlndXJhdGl" . "vbg=="), "_e69115f55c773363eecbe4bb66b360" . "3b" => base64_decode("RmFpbGVkIHRvIHNlbmQgbGljZW5zZSBsaW1pdCBub3RpZmljYXR" . "pb24sIGludmFsaWQgYWRkcmVzcyBzdXBwbGllZCBmb3IgbGljZW" . "5zZSdzIHJlc3BvbnNpYmxlIHBlcnNvbjog"), "_3780bbc04e696d98bd27a21ef" . "bc76917" => base64_decode("bGljZW5zZV9yZXNwb25zaWJsZ" . "V9lbWFpbA=="), "_be08ddade3" . "2f664e901ff" . "7dc3342cfc5" => base64_decode("PHA+UGxlYXNlIDxhIGh" . "yZWY9Ig=="), "_1ab9364741e2bcd0390100860" . "f733720" => base64_decode("c3lzdGVtT" . "mFtZQ=="), "_a1009d9" . "c49c875d" . "5b2778d6" . "52e37d30" . "1" => base64_decode("b2xk" . "X2Rh" . "dGE="), "_407f2538" . "9459aa722" . "2e0c3f82f" . "4860ec" => base64_decode("TUFYX0VYVFJBTkVUX1VT" . "RVJT"), "_f7813c29" . "06cd406c9" . "6fb53ba8f" . "1f67ed" => base64_decode("KSBoYXMgcmVhY2hlZCB0aGUgbGljZW5z" . "ZWQgbWF4aW11bS48L3A+"), "_54973ed5fac760db3f05" . "8610c2410459" => base64_decode("PHA+VGhlIG51bWJlciBvZiByZWdpc3RlcmVk" . "IHVzZXJzICg="), "_b0b89906f26b8b8c7f3465042f" . "dd65b8" => base64_decode("RmFpbGVkIHRvIHNlbmQgbGljZW" . "5zZSBsaW1pdCBub3RpZmljYXRp" . "b24sIGZhaWxlZCB0byBzZW5kIG" . "VtYWlsOiA="), "_0c519e721cc30" . "79fbb252fbd60f" . "d7904" => base64_decode("dGlt" . "ZQ=="), "_b10579d53" . "06e5a3556f" . "94720a7723" . "353" => base64_decode("cGVv" . "cGxl"), "_6be6964bc4ab7f79f775" . "67b06286e1e8" => base64_decode("c2VuZCBsaWNlbnNlIG5vdGlmaWNhdG" . "lvbg=="), "_96f48fef" . "e1c3f3f73" . "665787bab" . "3e6cdd" => base64_decode("RXJyb3IgcmVhZGluZ" . "yBsaWNlbnNlIGVtYW" . "lsIGFkZHJlc3M6IA=" . "="), "_285bdd252a49d46002d" . "babfdb4f3f8c0" => base64_decode("RmFpbGVkIHRvIHNlbmQgbGljZW5zZSBsaW1pdCBub3RpZmljYXRpb24sIGZhaWxlZCB0byBjb25zdHJ1Y3QgZW1" . "haWw6IA=="), "_7087eecf4b51c6e50" . "0737105ebb8d90d" => base64_decode("TUFYX1" . "VTRVJT"), "_1c214d18d1c15571573a94cdf029" . "a06a" => base64_decode("bGljZW5zZV9ub3RpZmljYXRpb25f" . "c2VudA=="), "_f9bdf7b1410533e" . "2bf209b22cd8b6ca" . "0" => base64_decode("Y2hlY2tMaWNlbnNlT25VcGRhd" . "GU="), "_50f3d86f340336be672ef20" . "f6b0f501c" => base64_decode("YmxvY2t" . "lZA=="), "_2ac2dbb9188d4357" . "1f0e27fe0c238349" => base64_decode("TGljZW5zZS" . "BMaW1pdCBy" . "ZWFjaGVkIG" . "ZvciA="), "_b3a4abf0a1aed28aa06645d748b8656" . "e" => base64_decode("L2FkbWluL3N5c3RlbS9saWN" . "lbnNl"), "_967d513abc37684f3b77c28" . "da28bee7e" => base64_decode("TUFYX1JFQU" . "RPTkxZX1VT" . "RVJT"), "_84cdca3be35ed61d8bfe2a" . "99137df437" => base64_decode("Y2hlY2tMaWNlbn" . "NlT25BZGQ="), "_3d8efc79f3244d8e1189" . "5ceca4830567" => base64_decode("Ij5yZXZpZXcgdGhl" . "IHN5c3RlbSBsaWNl" . "bnNlPC9hPi48L3A+"));
use Claromentis\Core\Audit\Audit;
use Claromentis\Core\Config\Exception\ValueException;
use Claromentis\Core\Event\GenericEvent;
use Claromentis\Core\Variable\DbVarService;
use Claromentis\People\Entity\User;
use Claromentis\People\Event\PeopleEventType;
use Claromentis\People\Event\AddUserEvent;
use Claromentis\People\Event\UpdateUserEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Claromentis\Core\License\License;
use Claromentis\Core\Http\HttpUtil;
use Claromentis\People\Repository\UserRepository;
use Claromentis\People\Service\UserLicenseCheck;
use Claromentis\Core\TextUtil\ClaText;
use Claromentis\Core\Config\Config;
use Claromentis\Core\Mail;
use Claromentis\Core\Mail\Send\MailFactory;
use Claromentis\Core\Mail\Exception\{Rfc822Exception, MailSendException, EmailInvalidException, AddressInvalidException};







class LicenseSubscriber implements EventSubscriberInterface
{
    
    
    
    
    
    
    private const NOTIFICATION_FREQUENCY = 86400;
    protected HttpUtil $httpUtil;
    protected License $license;
    protected UserRepository $userRepository;
    protected UserLicenseCheck $userLicense;
    protected DbVarService $dbVar;
    protected Audit $audit;
    protected ClaText $claText;
    private Mail\Api $mailApi;
    private MailFactory $mailFactory;
    protected Config $config;
    public function __construct(HttpUtil $httpUtil, License $_28d2607075b352d52b45daf2a256f773, UserRepository $_2462766b6a5ed9e85d4472e796fc20c0, UserLicenseCheck $_75f9f6357aabb3eddbca9ae1fec63bad, DbVarService $dbVar, Audit $audit, ClaText $_0f6231d620cefa9f483e066651e8bc61, Mail\Api $mailApi, MailFactory $_30975c67491190ff76aabd9b212b3323, Config $config)
    {
        $this->httpUtil = $httpUtil;
        $this->license = $_28d2607075b352d52b45daf2a256f773;
        $this->userRepository = $_2462766b6a5ed9e85d4472e796fc20c0;
        $this->userLicense = $_75f9f6357aabb3eddbca9ae1fec63bad;
        $this->dbVar = $dbVar;
        $this->audit = $audit;
        $this->claText = $_0f6231d620cefa9f483e066651e8bc61;
        $this->mailApi = $mailApi;
        $this->mailFactory = $_30975c67491190ff76aabd9b212b3323;
        $this->config = $config;
    }
    
    
    
    
    public static function getSubscribedEvents()
    {
        return [PeopleEventType::ADD_USER => [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_84cdca3b" . "e35ed61d8" . "bfe2a9913" . "7df437"], 100], PeopleEventType::UPDATE_USER => [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_f9bdf7b1410533e2bf209b2" . "2cd8b6ca0"], 100]];
    }
    public function checkLicenseOnAdd(AddUserEvent $_a4f2b121676574f14fa700fe53e39f8a)
    {
        $_65976ee34559dcb12bd6d5db68edf074 = $_a4f2b121676574f14fa700fe53e39f8a->GetUserId();
        
        
        $_24e0e36600d6af77406a44bb618a6253 = $this->userRepository->find($_65976ee34559dcb12bd6d5db68edf074);
        if ($_24e0e36600d6af77406a44bb618a6253 && $_24e0e36600d6af77406a44bb618a6253->isActive()) {
            $_8f9c021069172b13d82244b9a7585ad6 = $this->userLicense->checkLicenseLimitReached($_24e0e36600d6af77406a44bb618a6253, true, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7087eec" . "f4b51c6e" . "50073710" . "5ebb8d90" . "d"]);
            $_ba62a8b803bcffd82fc80036a66fc56b = $this->userLicense->checkLicenseLimitReached($_24e0e36600d6af77406a44bb618a6253, true, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_407f25389459aa7222e0c3f82f486" . "0ec"]);
            $_5b567ecdfd24b7e7a0864b9a8a23493d = $this->userLicense->checkLicenseLimitReached($_24e0e36600d6af77406a44bb618a6253, true, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_967d513abc37684f3b77c28da28bee7" . "e"]);
            if ($_8f9c021069172b13d82244b9a7585ad6 || $_ba62a8b803bcffd82fc80036a66fc56b || $_5b567ecdfd24b7e7a0864b9a8a23493d) {
                $type = $_ba62a8b803bcffd82fc80036a66fc56b ? $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_407f25389459aa7222e0c3f" . "82f4860ec"] : $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_7087eecf4" . "b51c6e5007" . "37105ebb8d" . "90d"];
                $this->sendNotification($_a4f2b121676574f14fa700fe53e39f8a, $type);
            }
        }
    }
    public function checkLicenseOnUpdate(UpdateUserEvent $_b37b3d22fca134bffd2e1a05ba46a30b)
    {
        $_65976ee34559dcb12bd6d5db68edf074 = $_b37b3d22fca134bffd2e1a05ba46a30b->GetUserId();
        
        
        $_24e0e36600d6af77406a44bb618a6253 = $this->userRepository->find($_65976ee34559dcb12bd6d5db68edf074);
        if (!$_24e0e36600d6af77406a44bb618a6253) {
            return;
        }
        $_a1009d9c49c875d5b2778d652e37d301 = $_b37b3d22fca134bffd2e1a05ba46a30b->hasArgument($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_a1009d9c49c875d5b2778d6" . "52e37d301"]) ? $_b37b3d22fca134bffd2e1a05ba46a30b->getArgument($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_a1009d9c49c875d5b2778d652e" . "37d301"]) : [];
        $_8e0b18f74a09ade273f09094f10ee1a5 = (bool) ($_a1009d9c49c875d5b2778d652e37d301[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_50f3d86f34033" . "6be672ef20f6b0" . "f501c"]] ?? true);
        $_8f9c021069172b13d82244b9a7585ad6 = $this->userLicense->checkLicenseLimitReached($_24e0e36600d6af77406a44bb618a6253, $_8e0b18f74a09ade273f09094f10ee1a5, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_7087eecf4b51c6e500737105ebb8d90" . "d"]);
        $_ba62a8b803bcffd82fc80036a66fc56b = $this->userLicense->checkLicenseLimitReached($_24e0e36600d6af77406a44bb618a6253, $_8e0b18f74a09ade273f09094f10ee1a5, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_407f253" . "89459aa7" . "222e0c3f" . "82f4860e" . "c"]);
        $_5b567ecdfd24b7e7a0864b9a8a23493d = $this->userLicense->checkLicenseLimitReached($_24e0e36600d6af77406a44bb618a6253, $_8e0b18f74a09ade273f09094f10ee1a5, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_967d513abc37" . "684f3b77c28da" . "28bee7e"]);
        if ($_8f9c021069172b13d82244b9a7585ad6 || $_ba62a8b803bcffd82fc80036a66fc56b || $_5b567ecdfd24b7e7a0864b9a8a23493d) {
            $type = $_ba62a8b803bcffd82fc80036a66fc56b ? $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_407f25389459aa7222e0c3f82f4860e" . "c"] : $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_7087eecf4b51c6e500737105ebb8d90" . "d"];
            $this->sendNotification($_b37b3d22fca134bffd2e1a05ba46a30b, $type);
        }
    }
    
    
    
    
    
    
    
    public function sendNotification(GenericEvent $event, string $type)
    {
        $_f0281cbb5034cf4151530b9fb3aa2296 = $this->dbVar->Get($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_1c214d18d1c1557" . "1573a94cdf029a06" . "a"]);
        
        
        if (!$_f0281cbb5034cf4151530b9fb3aa2296 || $_f0281cbb5034cf4151530b9fb3aa2296 < $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c519e721cc3079fbb252f" . "bd60fd7904"]() - self::NOTIFICATION_FREQUENCY) {
            try {
                $_ba0ce1ca53cccc31ea7894452bfca479 = $this->claText->HtmlSafe($this->config->get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_1ab9364741e2b" . "cd0390100860f7" . "33720"]));
                $_1b55708aa1d7c6796276f896d95438f8 = $this->claText->HtmlSafe($this->license->GetLicenseValue($type));
                $_04b543b96f8cd337fbddc92304b31404 = $this->claText->HtmlSafe($this->httpUtil->CreateInternalLink($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_b3a4abf0a1aed28aa06" . "645d748b8656e"]));
                $_1d6c68a0262e8fa0bed1215b7224a98e = $this->dbVar->Get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_3780bbc04e696d98bd27a21efb" . "c76917"]);
                if (empty($_1d6c68a0262e8fa0bed1215b7224a98e)) {
                    throw AddressInvalidException::invalidAddress($_1d6c68a0262e8fa0bed1215b7224a98e);
                }
                $_158022628d37e2deb506bb278d537259 = $this->mailFactory->createAddressFromRfc822Email($_1d6c68a0262e8fa0bed1215b7224a98e);
                $this->mailApi->createAndSendEmail($this->mailApi->createSystemAddress(), $_158022628d37e2deb506bb278d537259, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_2ac2dbb9188d43571f0e27fe0c238" . "349"] . $_ba0ce1ca53cccc31ea7894452bfca479, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_54973ed5fac760db3f058610c2410" . "459"] . $_1b55708aa1d7c6796276f896d95438f8 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_f7813c2906cd406c96fb53ba8f1f6" . "7ed"] . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_be08ddade32f664e901ff7dc3342c" . "fc5"] . $_04b543b96f8cd337fbddc92304b31404 . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_3d8efc79f" . "3244d8e118" . "95ceca4830" . "567"]);
            } catch (Rfc822Exception $exception) {
                $this->audit->Failure($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_b10579d5306e5a3" . "556f94720a772335" . "3"], $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_6be6964bc4" . "ab7f79f7756" . "7b06286e1e8"], $event->getUserId(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_2593d6a" . "d580eddd" . "65c8b5b7" . "ffd12459" . "d"] . $_1d6c68a0262e8fa0bed1215b7224a98e);
            } catch (AddressInvalidException $e) {
                $this->audit->Failure($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_b10579d5306e5a3556f94720a772" . "3353"], $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_6be6964bc4ab7f79f77567b0628" . "6e1e8"], $event->getUserId(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_e69115f55c773363eecb" . "e4bb66b3603b"] . $_1d6c68a0262e8fa0bed1215b7224a98e);
            } catch (MailSendException $exception) {
                $this->audit->Failure($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_b10579d5306e5a3556f94720a772" . "3353"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_6be6964bc4ab7f79f77567b06286e1" . "e8"], $event->getUserId(), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_b0b89906f26b8b8c7f3465042fdd6" . "5b8"] . $exception->getMessage());
            } catch (EmailInvalidException $exception) {
                $this->audit->Failure($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_b10579d5306e5a3556f94720a" . "7723353"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_6be6964bc4ab7" . "f79f77567b0628" . "6e1e8"], $event->getUserId(), $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_285bdd252a49d4" . "6002dbabfdb4f3f" . "8c0"] . $exception->getMessage());
            } catch (ValueException $exception) {
                $this->audit->Failure($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_b10579d5306e5a3556f94720a772335" . "3"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_6be6964bc4ab7f79f" . "77567b06286e1e8"], $event->getUserId(), $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_13626a711726e2d" . "f9aa25031d16575b" . "6"]);
            } catch (\Exception $exception) {
                $this->audit->Failure($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_b10579d5306e5a3556f94720a7723" . "353"], $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_6be6964bc4a" . "b7f79f77567b" . "06286e1e8"], $event->getUserId(), $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_96f48fefe1c3f3f73665787bab3e" . "6cdd"] . $exception->getMessage());
            } finally {
                $this->dbVar->Set($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_1c214d18" . "d1c155715" . "73a94cdf0" . "29a06a"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c519e721cc3079fbb252f" . "bd60fd7904"]());
            }
        }
    }
}