<?php

namespace App\Services\Providers;

use App\Models\ManagedEnvironment;
use RuntimeException;

final class ProviderConfigurationRequiredException extends RuntimeException
{
    public function __construct(
        public readonly int $tenantId,
        public readonly string $provider,
        public readonly string $reasonCode,
        public readonly ?string $extensionReasonCode = null,
        string $message = 'Provider configuration is required.',
    ) {
        parent::__construct($message);
    }

    public static function forTenant(ManagedEnvironment $tenant, string $provider, ProviderConnectionResolution $resolution): self
    {
        return new self(
            tenantId: (int) $tenant->getKey(),
            provider: $provider,
            reasonCode: $resolution->effectiveReasonCode(),
            extensionReasonCode: $resolution->extensionReasonCode,
            message: $resolution->message ?? 'Provider configuration is required.',
        );
    }
}
