<?php

use App\Services\Payments\ProviderRegistry;
use App\Services\Payments\Providers\StripeProvider;

test('can register payment provider', function () {
    $registry = new ProviderRegistry;
    $provider = new StripeProvider;

    $registry->register('stripe', $provider);

    expect($registry->has('stripe'))->toBeTrue();
    expect($registry->get('stripe'))->toBe($provider);
});

test('can get all providers', function () {
    $registry = new ProviderRegistry;
    $stripeProvider = new StripeProvider;

    $registry->register('stripe', $stripeProvider);

    $providers = $registry->getAllProviders();

    expect($providers)->toHaveCount(1);
    expect($providers->get('stripe'))->toBe($stripeProvider);
});

test('can get active providers only', function () {
    $registry = new ProviderRegistry;
    $stripeProvider = new StripeProvider;

    $registry->register('stripe', $stripeProvider);

    $activeProviders = $registry->getActiveProviders();

    expect($activeProviders)->toHaveCount(0); // Stripe is inactive without API key
});

test('can unregister provider', function () {
    $registry = new ProviderRegistry;
    $provider = new StripeProvider;

    $registry->register('stripe', $provider);
    expect($registry->has('stripe'))->toBeTrue();

    $result = $registry->unregister('stripe');
    expect($result)->toBeTrue();
    expect($registry->has('stripe'))->toBeFalse();
});

test('can validate providers', function () {
    $registry = new ProviderRegistry;
    $stripeProvider = new StripeProvider;

    $registry->register('stripe', $stripeProvider);

    $results = $registry->validateProviders();

    expect($results)->toHaveKey('stripe');
    expect($results['stripe']['active'])->toBeFalse();
    expect($results['stripe']['supports_recurring'])->toBeTrue();
    expect($results['stripe']['supports_one_time'])->toBeTrue();
});

test('can get provider statistics', function () {
    $registry = new ProviderRegistry;
    $stripeProvider = new StripeProvider;

    $registry->register('stripe', $stripeProvider);

    $stats = $registry->getProviderStats();

    expect($stats['total_providers'])->toBe(1);
    expect($stats['active_providers'])->toBe(0);
    expect($stats['recurring_providers'])->toBe(0);
    expect($stats['one_time_providers'])->toBe(0);
});
