<?php

namespace App\Services\DeveloperConfig;

use App\Http\Enum\CacheKeyEnum;
use App\Http\Enum\DevConfigKeyEnum;
use App\Models\DeveloperConfig;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;

class DeveloperConfigService
{

    public static function getDefaultExpireDay()
    {
        $expireTime = Carbon::now()->addHour();
        return Cache::remember(CacheKeyEnum::DEFAULT_EXPIRE_DAY, $expireTime, function () {
            $developerConfig = DeveloperConfig::query()->where("key",
                "=", DevConfigKeyEnum::SKU_EXPIRE_DAY)->first();
            return $developerConfig['value'] ?? DevConfigKeyEnum::DEFAULT_EXPIRE_DAY;
        });
    }

    public static function getSkuAdminRoleIds()
    {
        $expireTime = Carbon::now()->addHour();
        return Cache::remember(CacheKeyEnum::SKU_ADMIN_ROLE_IDS, $expireTime, function () {
            $developerConfig = DeveloperConfig::query()->where("key",
                "=", DevConfigKeyEnum::SKU_ADMIN_ROLE_IDS)->first();
            $roleIdsStr = $developerConfig['value'] ?? DevConfigKeyEnum::DEFAULT_SKU_ADMIN_ROLE_IDS;
            return explode(",", $roleIdsStr) ?? [];
        });
    }

}