<?php

namespace App\Helper\Cache;
use Modules\Admin\app\Models\CustomTheme;
use Illuminate\Support\Facades\Cache;
use App\Helper\Constant\CacheConstant;

class CustomThemeCacheHelper {
    public static $globals = 'custom-theme';
    public static $key = 'custom-theme';
    public static function getCacheCustomTheme(){
        $theme = Cache::get(self::$key, null);
        if (isset($GLOBALS[self::$globals]) && $theme != null)
            return $GLOBALS[self::$globals];
        if ($theme == null) {
            $theme = CustomTheme::first();
            if ($theme) {
                Cache::put(self::$key, json_encode($theme), (60 * CacheConstant::$expired) );
                $theme = json_encode($theme);
            } else {
                $theme = null;
            }
        }
        if ($theme == null) {
            $GLOBALS[self::$globals] = null;

        } else {
            $GLOBALS[self::$globals] = json_decode($theme);
        }
        return $GLOBALS[self::$globals];
    }

    public static function cleanCacheCustomTheme(){
        Cache::forget(self::$key);
    }
}
