<?php

declare(strict_types=1);

namespace HyperfTest\Cases\Unit\Service;

use App\Service\MqStatusService;
use Hyperf\Contract\ConfigInterface;
use PHPUnit\Framework\TestCase;

/**
 * MqStatusService 单元测试
 *
 * 覆盖队列类型常量、状态判定逻辑
 *
 * @internal
 * @coversNothing
 */
class MqStatusServiceTest extends TestCase
{
    private MqStatusService $service;

    protected function setUp(): void
    {
        parent::setUp();

        $config = $this->createMock(ConfigInterface::class);
        $this->service = new MqStatusService($config);
    }

    // ========== getValidQueueTypes ==========

    public function test_get_valid_queue_types_returns_correct_list(): void
    {
        $types = $this->service->getValidQueueTypes();

        $this->assertIsArray($types);
        $this->assertContains('orders', $types);
        $this->assertContains('products', $types);
        $this->assertContains('refunds', $types);
        $this->assertContains('inventory', $types);
        $this->assertCount(4, $types);
    }

    // ========== getQueueStatus 状态判定 ==========

    public function test_status_high_load_when_messages_over_100(): void
    {
        $this->assertSame('high_load', $this->service->getQueueStatus(101));
        $this->assertSame('high_load', $this->service->getQueueStatus(500));
        $this->assertSame('high_load', $this->service->getQueueStatus(10000));
    }

    public function test_status_processing_when_messages_over_10(): void
    {
        $this->assertSame('processing', $this->service->getQueueStatus(11));
        $this->assertSame('processing', $this->service->getQueueStatus(50));
        $this->assertSame('processing', $this->service->getQueueStatus(100));
    }

    public function test_status_active_when_messages_over_0(): void
    {
        $this->assertSame('active', $this->service->getQueueStatus(1));
        $this->assertSame('active', $this->service->getQueueStatus(5));
        $this->assertSame('active', $this->service->getQueueStatus(10));
    }

    public function test_status_empty_when_no_messages(): void
    {
        $this->assertSame('empty', $this->service->getQueueStatus(0));
    }

    // ========== 边界值测试 ==========

    public function test_status_boundary_at_exactly_100(): void
    {
        // 100 条消息 → processing（> 10 且 <= 100）
        $this->assertSame('processing', $this->service->getQueueStatus(100));
    }

    public function test_status_boundary_at_exactly_10(): void
    {
        // 10 条消息 → active（> 0 且 <= 10）
        $this->assertSame('active', $this->service->getQueueStatus(10));
    }

    public function test_status_boundary_at_exactly_1(): void
    {
        $this->assertSame('active', $this->service->getQueueStatus(1));
    }

    // ========== QUEUE_TYPES 常量 ==========

    public function test_queue_types_constant_matches_valid_types(): void
    {
        $this->assertSame(
            MqStatusService::QUEUE_TYPES,
            $this->service->getValidQueueTypes()
        );
    }
}
