<?php

namespace KupShop\KupShopBundle\Util\System;

use KupShop\KupShopBundle\Template\ObjectWrapper;

class CustomSettingsWrapper extends ObjectWrapper
{
    public function setObject($object)
    {
        $this->object = (object) $object;

        return $this;
    }

    public function offsetExists($offset): bool
    {
        if ($this->checkRequireAdmin($offset)) {
            return false;
        }

        return parent::offsetExists($offset);
    }

    public function offsetGet($offset): mixed
    {
        if ($this->checkRequireAdmin($offset)) {
            return false;
        }

        return parent::offsetGet($offset);
    }

    public function checkRequireAdmin($offset)
    {
        if (strpos($offset, '_adminSetter') === false && !getAdminUser() && !empty($this->{$offset.'_adminSetter'}) && $this->{$offset.'_adminSetter'} == 'Y') {
            return true;
        }

        return false;
    }

    public function jsonSerialize(): mixed
    {
        return $this->getObject();
    }
}
