<?php

namespace App\Helpers;

use App\Models\Setting;

class SettingHelper
{
    private static ?array $cache = null;

    public static function get(): array
    {
        if (self::$cache !== null) {
            return self::$cache;
        }

        $pdo = Database::connection();
        $setting = (new Setting($pdo))->get();

        if (empty($setting)) {
            $setting = [
                'company_name' => 'Mutiara Group',
                'tagline' => 'Smart HR Portal',
                'email' => null,
                'phone' => null,
                'address' => null,
                'logo_path' => null,
                'locations' => [],
            ];
        } elseif (!isset($setting['locations'])) {
            $setting['locations'] = [];
        }

        return self::$cache = $setting;
    }

    public static function refresh(): void
    {
        self::$cache = null;
    }
}

