<?php
namespace Claromentis\Core\Config;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] ?: array()) + array("_87daa84e346f6420a3" . "f3426e05d16a7b" => base64_decode("L" . "w" . "=" . "="), "_5e30c4717" . "ced36cff9e" . "93e19a5c57" . "6cc" => base64_decode("aXNfc3RyaW" . "5n"), "_a591754a8ddcdbda9c80f1db4d911" . "e14" => base64_decode("aXNfbnVsbA" . "=="), "_969f86ee5d83b38875" . "e46ca1ba755446" => base64_decode("Lm" . "pz" . "b2" . "4="), "_6111ca842f30" . "99581091d64a8" . "21e8726" => base64_decode("QmFzZSB" . "kaXJlY3" . "RvcnkgZ" . "m9yICc="), "_d8100fa0c22f8cc" . "8d79b337a862d5f6" . "e" => base64_decode("JyBKU09OIGNvbmZpZw" . "=="), "_356f9f238fd14c90f5d7eb0d07" . "a99010" => base64_decode("JyBKU09OIGNvbmZpZ3VyYXRpb24gbXVz" . "dCBiZSBhIHN0cmluZyBvciBhbiBpbnN0" . "YW5jZSBvZiA="), "_a412a7e6c3254" . "d0af8eb8263e90" . "bfe7b" => base64_decode("VW5kZWZpbmVkIGJ" . "hc2UgZGlyZWN0b3" . "J5IGZvciAn"), "_bd71c3b5c201fc11db8" . "2ed14ce424de5" => base64_decode("aW5fYXJ" . "yYXk="));
use Claromentis\Core\Config\Exception\LoadException;
use Claromentis\Core\Json;
use InvalidArgumentException;
use RuntimeException;




class ConfigJson implements WritableConfig
{
    
    
    
    
    
    
    protected $configDir;
    
    
    
    
    protected string $appCode;
    
    
    
    
    protected array $denyList = [];
    
    
    
    
    
    
    protected ?array $data;
    
    
    
    
    protected ?Json\JsonFile $jsonFile;
    
    
    
    
    
    
    
    
    public function __construct($_864529c9184047572d3b64359693a6ab, string $_12aacc24efb41c22660a144b2f87be64, $_a39c14405e25e4f7913db1ad152a599d = [])
    {
        if (!$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_5e30c4717ced36cff" . "9e93e19a5c576cc"]($_864529c9184047572d3b64359693a6ab) && !$_864529c9184047572d3b64359693a6ab instanceof ConfigValue) {
            throw new InvalidArgumentException($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_6111ca842f3099581091d64a821e87" . "26"] . $_12aacc24efb41c22660a144b2f87be64 . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_356f9f238fd14c90f5d7eb" . "0d07a99010"] . ConfigValue::class);
        }
        $this->configDir = $_864529c9184047572d3b64359693a6ab;
        $this->appCode = $_12aacc24efb41c22660a144b2f87be64;
        $this->denyList = $_a39c14405e25e4f7913db1ad152a599d;
        $this->data = null;
    }
    
    
    
    
    public function load()
    {
        try {
            $this->data = $this->removeDenyListValues($this->readJsonFile());
        } catch (Json\ReadException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->data = [];
            throw new LoadException($_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage(), $_fe441aa3ef350bfb1a1a1ad8520dd530->getCode(), $_fe441aa3ef350bfb1a1a1ad8520dd530);
        }
    }
    public function has(string $key) : bool
    {
        return $this->get($key) !== null;
    }
    
    
    
    
    
    
    
    public function get(string $key)
    {
        
        
        if (!$this->canSet($key)) {
            return null;
        }
        if ($this->data === null) {
            $this->load();
        }
        return isset($this->data[$key]) ? $this->data[$key] : null;
    }
    
    
    
    
    
    
    
    public function set(string $key, $value) : void
    {
        if (!$this->canSet($key)) {
            return;
        }
        if ($this->data === null) {
            $this->load();
        }
        $this->data[$key] = $value;
    }
    public function setMany(array $values) : void
    {
        foreach ($values as $key => $value) {
            $this->set($key, $value);
        }
    }
    
    
    
    
    
    
    public function getAll() : array
    {
        if ($this->data === null) {
            $this->load();
        }
        return $this->data ?? [];
    }
    
    
    
    
    
    
    public function delete(string $key) : void
    {
        if (isset($this->data[$key])) {
            unset($this->data[$key]);
        }
    }
    
    
    
    
    public function save() : void
    {
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_a591754a8ddcdb" . "da9c80f1db4d911" . "e14"]($this->data)) {
            return;
        }
        $this->getJsonFile()->Write($this->data);
    }
    
    
    
    
    
    
    
    public function canSet(string $key) : bool
    {
        return !$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_bd71c3b5c201fc1" . "1db82ed14ce424de" . "5"]($key, $this->denyList);
    }
    
    
    
    
    
    
    public function getConfigDir() : string
    {
        return (string) $this->configDir;
    }
    
    
    
    
    
    
    
    
    protected function readJsonFile()
    {
        return $this->getJsonFile()->Read();
    }
    
    
    
    
    
    
    
    
    protected function getJsonFile()
    {
        $_864529c9184047572d3b64359693a6ab = $this->getConfigDir();
        $_12aacc24efb41c22660a144b2f87be64 = $this->appCode;
        if (empty($this->configDir)) {
            throw new RuntimeException($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_a412a7e6c3254d0af8eb8263" . "e90bfe7b"] . $_12aacc24efb41c22660a144b2f87be64 . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_d8100fa0" . "c22f8cc8d" . "79b337a86" . "2d5f6e"]);
        }
        $_e8b59c8294156e6d075d01ecdec9001f = $_864529c9184047572d3b64359693a6ab . $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_87daa84e346f6" . "420a3f3426e05d" . "16a7b"] . $_12aacc24efb41c22660a144b2f87be64 . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_969f86ee5d83b38875" . "e46ca1ba755446"];
        if (!isset($this->jsonFile) || $this->jsonFile->GetFilePath() !== $_e8b59c8294156e6d075d01ecdec9001f) {
            $this->jsonFile = new Json\JsonFile($_e8b59c8294156e6d075d01ecdec9001f);
        }
        return $this->jsonFile;
    }
    
    
    
    
    
    
    
    protected function removeDenyListValues(array $values)
    {
        foreach ($this->denyList as $key) {
            unset($values[$key]);
        }
        return $values;
    }
    public function offsetGet($_1f50e30be8c2fefa6881834e71d504a2)
    {
        return $this->get($_1f50e30be8c2fefa6881834e71d504a2);
    }
    public function offsetExists($_1f50e30be8c2fefa6881834e71d504a2) : bool
    {
        return $this->has($_1f50e30be8c2fefa6881834e71d504a2);
    }
    public function offsetSet($_1f50e30be8c2fefa6881834e71d504a2, $value) : void
    {
        $this->set($_1f50e30be8c2fefa6881834e71d504a2, $value);
    }
    public function offsetUnset($_1f50e30be8c2fefa6881834e71d504a2) : void
    {
        $this->delete($_1f50e30be8c2fefa6881834e71d504a2);
    }
}