<?php

namespace App\Support;

use App\Services\Settings\SettingService;

class PlatformName
{
    public static function resolve(): string
    {
        if (! app(InstallationState::class)->isInstalled()) {
            return config('app.name', config('installer.product_name', 'Admin'));
        }

        try {
            $name = app(SettingService::class)->get('app.name');

            if (is_string($name) && $name !== '') {
                return $name;
            }
        } catch (\Throwable) {
            // Settings may be unavailable during early boot.
        }

        return config('app.name', 'Admin');
    }

    public static function applyToConfig(): void
    {
        config(['app.name' => self::resolve()]);
    }
}
