<?php

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

class PackagesCacheHelper {
    public static $key = 'packages';
    public static function getCachePackages():array|null
    {
        $packages = Cache::get(self::$key, null);
        if ($packages==null) {
            $packages = Package::all();
            if ($packages!=null) {
                Cache::put(self::$key, json_encode($packages), (60 * CacheConstant::$expired) );
                $packages = json_encode($packages);
            } else {
                $packages = null;
            }
        }
        if($packages!=null){
            return json_decode($packages);
        }

        return null;
    }

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