<?php

namespace Tests\Feature;

use App\Filament\Widgets\QueueHealthWidget;
use App\Filament\Widgets\UploadPipelineHealthWidget;
use Illuminate\Support\Facades\Cache;
use Livewire\Livewire;
use Tests\TestCase;

class OpsHealthWidgetsTest extends TestCase
{
    public function test_queue_health_widget_renders_without_snapshot(): void
    {
        app()->setLocale('en');
        Cache::forget('storage:queue-health:last');

        Livewire::test(QueueHealthWidget::class)
            ->assertStatus(200)
            ->assertSee(__('admin.ops_health.queue.no_snapshot'));
    }

    public function test_queue_health_widget_renders_with_snapshot(): void
    {
        app()->setLocale('en');
        Cache::put('storage:queue-health:last', [
            'generated_at' => now()->toIso8601String(),
            'connection' => 'redis',
            'queues' => [
                [
                    'queue' => 'default',
                    'size' => 120,
                    'failed' => 2,
                    'severity' => 'warning',
                    'limits' => [
                        'warning' => 100,
                        'critical' => 200,
                    ],
                ],
            ],
            'alerts' => [
                [
                    'queue' => 'default',
                    'type' => 'size',
                    'severity' => 'warning',
                    'size' => 120,
                ],
            ],
            'stalled_assets' => 1,
        ], now()->addMinutes(5));

        Livewire::test(QueueHealthWidget::class)
            ->assertStatus(200)
            ->assertSee('default')
            ->assertSee(__('admin.ops_health.queue.alerts_heading'));
    }

    public function test_upload_pipeline_widget_renders_without_snapshot(): void
    {
        app()->setLocale('en');
        Cache::forget('storage:monitor:last');

        Livewire::test(UploadPipelineHealthWidget::class)
            ->assertStatus(200)
            ->assertSee(__('admin.ops_health.pipeline.no_snapshot'));
    }
}
