<?php

declare(strict_types=1);

final class MyronExtensionSDK
{
    public function __construct(private readonly string $vendor)
    {
    }

    /**
     * @return array{site_name:string,site_url:string,language:string,timezone:string}
     */
    public function getSiteSettings(): array
    {
        $settings = myronSiteSettings();

        return [
            'site_name' => (string) ($settings['site_title'] ?? myronSiteTitle()),
            'site_url' => function_exists('myronAppUrl') ? myronAppUrl() : (string) (getenv('MYRON_APP_URL') ?: ''),
            'language' => myronSiteLanguage(),
            'timezone' => myronSiteTimezone(),
        ];
    }

    public function getSiteType(): string
    {
        try {
            $bundleId = myronBundleActivationRepository()->getPrimaryBundleId();
            if (is_string($bundleId) && trim($bundleId) !== '') {
                return $bundleId;
            }
        } catch (Throwable) {
        }

        return 'site-type.universal';
    }

    /**
     * @param array<string, scalar|null> $query
     */
    public function buildAdminUrl(string $route, array $query = []): string
    {
        return myronBuildAdminUrl($route, $query);
    }

    public function buildAssetUrl(string $path): string
    {
        return myronBuildAssetUrl($path);
    }

    public function getVendor(): string
    {
        return $this->vendor;
    }

    public function coreSourceEditingSupported(): bool
    {
        return false;
    }
}
