<?php

namespace Tests\Feature;

use App\Models\DamageFinding;
use App\Models\Inspection;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class LiveSummaryTest extends TestCase
{
    use RefreshDatabase;

    public function test_live_summary_returns_authenticated_user_counts(): void
    {
        $user = User::factory()->create(['role' => 'Inspector']);
        $otherUser = User::factory()->create(['role' => 'Inspector']);
        $inspection = Inspection::query()->create([
            'user_id' => $user->id,
            'property_name' => 'Live Summary House',
            'status' => 'review',
            'ai_confidence' => 91.2,
            'estimated_cost' => 3000000,
            'scheduled_at' => now(),
        ]);

        DamageFinding::query()->create([
            'inspection_id' => $inspection->id,
            'category' => 'Roof leak',
            'severity' => 'high',
            'status' => 'review',
            'confidence' => 92.1,
            'estimated_repair_cost' => 1500000,
        ]);
        $otherInspection = Inspection::query()->create([
            'user_id' => $otherUser->id,
            'property_name' => 'Other Live Summary House',
            'status' => 'review',
            'ai_confidence' => 91.2,
            'estimated_cost' => 9000000,
            'scheduled_at' => now(),
        ]);
        DamageFinding::query()->create([
            'inspection_id' => $otherInspection->id,
            'category' => 'Other leak',
            'severity' => 'high',
            'status' => 'review',
            'confidence' => 92.1,
            'estimated_repair_cost' => 9000000,
        ]);

        $response = $this->actingAs($user)->getJson('/live/summary');

        $response->assertOk();
        $response->assertJsonPath('totalInspections', 1);
        $response->assertJsonPath('detectedDamages', 1);
        $response->assertJsonPath('needsReview', 1);
        $response->assertJsonPath('estimatedCost', 3000000);
        $response->assertJsonPath('repairCost', 1500000);
    }
}
