<?php

namespace App\Support\Links;

use App\Filament\Resources\TenantResource;
use App\Models\Tenant;

final class RequiredPermissionsLinks
{
    private const ADMIN_CONSENT_GUIDE_URL = 'https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/grant-admin-consent';

    /**
     * @param  array<string, mixed>  $filters
     */
    public static function requiredPermissions(Tenant $tenant, array $filters = []): string
    {
        $base = sprintf('/admin/tenants/%s/required-permissions', urlencode((string) $tenant->external_id));

        if ($filters === []) {
            return $base;
        }

        $query = http_build_query($filters);

        return $query !== '' ? "{$base}?{$query}" : $base;
    }

    public static function adminConsentUrl(Tenant $tenant): ?string
    {
        return TenantResource::adminConsentUrl($tenant);
    }

    public static function adminConsentGuideUrl(): string
    {
        return self::ADMIN_CONSENT_GUIDE_URL;
    }

    public static function adminConsentPrimaryUrl(Tenant $tenant): string
    {
        return self::adminConsentUrl($tenant) ?? self::adminConsentGuideUrl();
    }
}
