<?php

namespace Kylin\Payment\Tests\Unit;

use Illuminate\Foundation\Testing\TestCase;
use Kylin\Payment\Providers\PaymentServiceProvider;
use Kylin\Payment\Payment;
use Kylin\Payment\PaymentManager;
use Kylin\Payment\Services\ConfigCacheService;
use Kylin\Payment\Services\PaymentRecordService;
use Kylin\Payment\Services\PaymentCallbackLogService;
use Kylin\Payment\Services\PaymentStatisticsService;
use Kylin\Payment\Services\LanguageService;
use Kylin\Payment\Services\QueueService;
use Kylin\Payment\Services\PaymentScenarioService;
use Kylin\Payment\Services\SecurityService;
use Kylin\Payment\Services\VersionManagerService;
use Kylin\Payment\Services\TestToolService;
use Kylin\Payment\Services\NotificationService;
use Kylin\Payment\Services\QrCodeService;
use Kylin\Payment\Services\PaymentLinkService;
use Kylin\Payment\Services\ProfitSharingService;
use Kylin\Payment\Services\CouponService;
use Kylin\Payment\Services\ReportService;
use Kylin\Payment\Services\PaymentRetryService;
use Kylin\Payment\Services\PaymentTimeoutService;
use Kylin\Payment\Services\PaymentPreCreateService;
use Kylin\Payment\Services\PaymentDataMaskingService;
use Kylin\Payment\Services\PaymentRateLimitService;
use Kylin\Payment\Services\PaymentWebhookService;
use Kylin\Payment\Services\PaymentIntelligentRoutingService;
use Kylin\Payment\Services\PaymentBatchOperationService;

class PaymentServiceProviderTest extends TestCase
{
    /**
     * 测试服务提供者是否正确注册
     */
    public function testServiceProviderRegistersServices()
    {
        // 确保服务提供者已经注册
        $this->app->register(PaymentServiceProvider::class);

        // 测试支付服务
        $payment = $this->app->make(Payment::class);
        $this->assertInstanceOf(Payment::class, $payment);

        // 测试支付管理器
        $manager = $this->app->make(PaymentManager::class);
        $this->assertInstanceOf(PaymentManager::class, $manager);

        // 测试配置缓存服务
        $configCacheService = $this->app->make(ConfigCacheService::class);
        $this->assertInstanceOf(ConfigCacheService::class, $configCacheService);

        // 测试支付记录服务
        $paymentRecordService = $this->app->make(PaymentRecordService::class);
        $this->assertInstanceOf(PaymentRecordService::class, $paymentRecordService);

        // 测试回调日志服务
        $callbackLogService = $this->app->make(PaymentCallbackLogService::class);
        $this->assertInstanceOf(PaymentCallbackLogService::class, $callbackLogService);

        // 测试支付统计服务
        $paymentStatisticsService = $this->app->make(PaymentStatisticsService::class);
        $this->assertInstanceOf(PaymentStatisticsService::class, $paymentStatisticsService);

        // 测试语言服务
        $languageService = $this->app->make(LanguageService::class);
        $this->assertInstanceOf(LanguageService::class, $languageService);

        // 测试队列服务
        $queueService = $this->app->make(QueueService::class);
        $this->assertInstanceOf(QueueService::class, $queueService);

        // 测试支付场景服务
        $paymentScenarioService = $this->app->make(PaymentScenarioService::class);
        $this->assertInstanceOf(PaymentScenarioService::class, $paymentScenarioService);

        // 测试安全服务
        $securityService = $this->app->make(SecurityService::class);
        $this->assertInstanceOf(SecurityService::class, $securityService);

        // 测试版本管理服务
        $versionManagerService = $this->app->make(VersionManagerService::class);
        $this->assertInstanceOf(VersionManagerService::class, $versionManagerService);

        // 测试测试工具服务
        $testToolService = $this->app->make(TestToolService::class);
        $this->assertInstanceOf(TestToolService::class, $testToolService);

        // 测试通知服务
        $notificationService = $this->app->make(NotificationService::class);
        $this->assertInstanceOf(NotificationService::class, $notificationService);

        // 测试二维码服务
        $qrCodeService = $this->app->make(QrCodeService::class);
        $this->assertInstanceOf(QrCodeService::class, $qrCodeService);

        // 测试支付链接服务
        $paymentLinkService = $this->app->make(PaymentLinkService::class);
        $this->assertInstanceOf(PaymentLinkService::class, $paymentLinkService);

        // 测试分账服务
        $profitSharingService = $this->app->make(ProfitSharingService::class);
        $this->assertInstanceOf(ProfitSharingService::class, $profitSharingService);

        // 测试优惠券服务
        $couponService = $this->app->make(CouponService::class);
        $this->assertInstanceOf(CouponService::class, $couponService);

        // 测试报表服务
        $reportService = $this->app->make(ReportService::class);
        $this->assertInstanceOf(ReportService::class, $reportService);

        // 测试支付重试服务
        $paymentRetryService = $this->app->make(PaymentRetryService::class);
        $this->assertInstanceOf(PaymentRetryService::class, $paymentRetryService);

        // 测试支付超时处理服务
        $paymentTimeoutService = $this->app->make(PaymentTimeoutService::class);
        $this->assertInstanceOf(PaymentTimeoutService::class, $paymentTimeoutService);

        // 测试支付预创建服务
        $paymentPreCreateService = $this->app->make(PaymentPreCreateService::class);
        $this->assertInstanceOf(PaymentPreCreateService::class, $paymentPreCreateService);

        // 测试支付数据脱敏服务
        $paymentDataMaskingService = $this->app->make(PaymentDataMaskingService::class);
        $this->assertInstanceOf(PaymentDataMaskingService::class, $paymentDataMaskingService);

        // 测试支付接口限流服务
        $paymentRateLimitService = $this->app->make(PaymentRateLimitService::class);
        $this->assertInstanceOf(PaymentRateLimitService::class, $paymentRateLimitService);

        // 测试支付Webhook服务
        $paymentWebhookService = $this->app->make(PaymentWebhookService::class);
        $this->assertInstanceOf(PaymentWebhookService::class, $paymentWebhookService);

        // 测试支付智能路由服务
        $paymentIntelligentRoutingService = $this->app->make(PaymentIntelligentRoutingService::class);
        $this->assertInstanceOf(PaymentIntelligentRoutingService::class, $paymentIntelligentRoutingService);

        // 测试支付批量操作服务
        $paymentBatchOperationService = $this->app->make(PaymentBatchOperationService::class);
        $this->assertInstanceOf(PaymentBatchOperationService::class, $paymentBatchOperationService);
    }

    /**
     * 测试服务提供者是否正确注册了门面
     */
    public function testServiceProviderRegistersFacade()
    {
        // 确保服务提供者已经注册
        $this->app->register(PaymentServiceProvider::class);

        // 测试门面是否可用
        $this->assertTrue(class_exists('\Payment'));
        $this->assertTrue(class_exists('\Kylin\Payment\Facades\Payment'));
    }
}
