<?php

namespace Tests\Feature;

use App\Models\Activity;
use App\Models\Client;
use App\Models\Document;
use App\Models\FieldJob;
use App\Models\Import;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class DashboardTest extends TestCase
{
    use RefreshDatabase;

    public function test_dashboard_returns_kpis_and_trends(): void
    {
        $user = User::factory()->create();
        $this->actingAs($user);

        Client::factory()->create();
        Document::factory()->create();
        FieldJob::factory()->create();
        Import::factory()->create(['status' => 'queued']);
        Activity::factory()->create();

        $response = $this->get('/dashboard');
        $response->assertSuccessful();

        $props = $response->inertiaProps();

        $this->assertArrayHasKey('kpis', $props);
        $this->assertArrayHasKey('trends', $props);
        foreach (['clients_total', 'clients_new_7d', 'field_jobs_today', 'documents_today', 'active_imports', 'active_contracts'] as $k) {
            $this->assertArrayHasKey($k, $props['kpis']);
        }
        foreach (['clients_new', 'documents_new', 'field_jobs', 'imports_new', 'labels'] as $k) {
            $this->assertArrayHasKey($k, $props['trends']);
        }
    }
}
