<?php

namespace App\Helpers;

use App\Models\Setting;
use Illuminate\Support\Facades\Cache;

class SettingsHelper
{
    public static function get(string $key, mixed $default = null): mixed
    {
        $settings = Cache::remember('app_settings', 3600, function () {
            return Setting::pluck('value', 'key')->all();
        });

        return $settings[$key] ?? $default;
    }

    public static function all(): array
    {
        return Cache::remember('app_settings', 3600, function () {
            return Setting::pluck('value', 'key')->all();
        });
    }

    public static function clear(): void
    {
        Cache::forget('app_settings');
    }
}
