<?php
namespace Claromentis\Orgchart\Service;

$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_bfc5170c8" . "b7d456e4b7" . "ec76531900" . "d6f" => base64_decode("dmlld19w" . "cm9maWxl"), "_0c5123aa744f69bbc0e" . "8b3ea2f6e847d" => base64_decode("bG" . "1z" . "Zw" . "=="), "_d706c160e" . "45bf7434ff" . "f82a5976f0" . "e19" => base64_decode("YXJyYXlfa2V5" . "cw=="), "_6596b8f6a4969f9a3f6a1b2" . "2b90e9331" => base64_decode("c3ByaW" . "50Zg=="), "_a1bae7b2f" . "58b89d3507" . "1fc45f2e1a" . "780" => base64_decode("b3JnY2hhcnQu" . "YWRtaW4uZHVw" . "bGljYXRlX2Zp" . "ZWxkX3ZhbHVl"), "_bd71c3b5c201fc11d" . "b82ed14ce424de5" => base64_decode("aW5fYX" . "JyYXk="), "tit" . "le" => base64_decode("dG" . "l0" . "bG" . "U="));
use Claromentis\Core\Config\WritableConfig;
use Claromentis\Orgchart\OrgchartApplication;
use Claromentis\People\UserFieldsConfigService;
class OrgchartProfileFieldService
{
    const EMPTY_OPTION = '';
    const CONFIG_KEY = 'profile_fields';
    const PRIMARY_FIELD_KEY = 'primary_field', SECONDARY_FIELD_KEY = 'secondary_field', CUSTOM_FIELD_1_KEY = 'custom_field_1', CUSTOM_FIELD_2_KEY = 'custom_field_2', CUSTOM_FIELD_3_KEY = 'custom_field_3';
    private UserFieldsConfigService $userFieldsConfigService;
    private WritableConfig $config;
    public function __construct(UserFieldsConfigService $userFieldsConfigService)
    {
        $this->userFieldsConfigService = $userFieldsConfigService;
        $this->config = OrgchartApplication::getConfig();
    }
    
    
    
    
    public function UpdateProfileFields(array $data)
    {
        $_e45e25de1a61237ac99b07b1a8be92b3 = [];
        $_9116ae0727c2ff12b87083d6b9eafcb6 = [];
        foreach ($data as $code => $_13d133c615714d50832f54e91fea8fb0) {
            if (!OrgchartProfileFieldService::FieldKeyExists($code) || !$this->ProfileFieldExists($_13d133c615714d50832f54e91fea8fb0) || $_13d133c615714d50832f54e91fea8fb0 == static::EMPTY_OPTION) {
                continue;
            }
            if ($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_bd71c3b5c201fc11db82ed14ce42" . "4de5"]($_13d133c615714d50832f54e91fea8fb0, $_9116ae0727c2ff12b87083d6b9eafcb6)) {
                $_58ca0626eba249b8a74733ff5ccf3280 = $this->userFieldsConfigService->GetAllFieldsForMode($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_bfc5170c" . "8b7d456e4" . "b7ec76531" . "900d6f"]);
                throw new \Exception($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_6596b8f6a4969f9a3f6a1b22b90e933" . "1"]($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0c5123aa744f" . "69bbc0e8b3ea2" . "f6e847d"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_a1bae7b2f58b89d350" . "71fc45f2e1a780"]), $_58ca0626eba249b8a74733ff5ccf3280[$_13d133c615714d50832f54e91fea8fb0][$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["ti" . "tl" . "e"]]));
            }
            $_9116ae0727c2ff12b87083d6b9eafcb6[] = $_13d133c615714d50832f54e91fea8fb0;
            $_e45e25de1a61237ac99b07b1a8be92b3[$code] = $_13d133c615714d50832f54e91fea8fb0;
        }
        $this->config->set(static::CONFIG_KEY, $_e45e25de1a61237ac99b07b1a8be92b3);
        $this->config->save();
    }
    public static function GetFieldKeys() : array
    {
        return [static::PRIMARY_FIELD_KEY, static::SECONDARY_FIELD_KEY, static::CUSTOM_FIELD_1_KEY, static::CUSTOM_FIELD_2_KEY, static::CUSTOM_FIELD_3_KEY];
    }
    private function GetProfileFields() : array
    {
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d706c160e45bf7434fff8" . "2a5976f0e19"]($this->userFieldsConfigService->GetAllFieldsForMode($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_bfc5170c8b7d456e4b7ec76531900d6" . "f"]));
    }
    private static function FieldKeyExists(string $key) : bool
    {
        return $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_bd71c3b5" . "c201fc11d" . "b82ed14ce" . "424de5"]($key, static::GetFieldKeys());
    }
    public function ProfileFieldExists(string $_13d133c615714d50832f54e91fea8fb0) : bool
    {
        return $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bd71c3b5c" . "201fc11db8" . "2ed14ce424" . "de5"]($_13d133c615714d50832f54e91fea8fb0, $this->GetProfileFields());
    }
}