<?php

use App\Filament\Widgets\StatsOverviewWidget;
use App\Models\ApiLog;
use App\Models\Station;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
    $this->admin = User::factory()->admin()->create();
    $this->actingAs($this->admin);
});

it('renders the stats overview widget', function () {
    User::factory()->count(3)->create();
    Station::factory()->count(2)->create();

    DB::table('weekly_forecasts')->insert([
        'forecast_for' => now()->next(Carbon::MONDAY)->toDateString(),
        'model_version' => 'ridge-v1-test',
        'direction' => 'rising',
        'magnitude_pence' => 80,
        'ridge_confidence' => 65,
        'flagged_duty_change' => false,
        'reasoning' => 'test',
        'generated_at' => now()->subHours(2),
        'created_at' => now(),
        'updated_at' => now(),
    ]);

    ApiLog::factory()->count(2)->create(['status_code' => 200, 'error' => null, 'created_at' => now()->subMinutes(30)]);

    Livewire::test(StatsOverviewWidget::class)
        ->assertOk();
});
