<?php

namespace Tests\Feature\FinanceAssistantAI;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Tests\Traits\CreatesUsers;

class FinanceAssistantAIDashboardTest extends TestCase
{
    use CreatesUsers;
    use RefreshDatabase;

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

        $this->ensureSettingsExist();
    }

    public function test_guest_cannot_access_finance_ai_dashboard(): void
    {
        $response = $this->get('/finance-assistant-ai');

        $response->assertRedirect('/auth/login');
    }

    public function test_authenticated_user_can_access_finance_ai_dashboard(): void
    {
        $user = $this->createAdmin();

        $response = $this->actingAs($user)->get('/finance-assistant-ai');

        $response->assertStatus(200);
        $response->assertViewIs('financeassistantai::index');
    }

    public function test_dashboard_displays_financial_stats(): void
    {
        $user = $this->createAdmin();

        $response = $this->actingAs($user)->get('/finance-assistant-ai');

        $response->assertStatus(200);
        $response->assertSee('Monthly Income');
        $response->assertSee('Monthly Expenses');
        $response->assertSee('Net Profit');
        $response->assertSee('Current Balance');
    }

    public function test_dashboard_displays_quick_actions(): void
    {
        $user = $this->createAdmin();

        $response = $this->actingAs($user)->get('/finance-assistant-ai');

        $response->assertStatus(200);
        $response->assertSee('Start Chat');
        $response->assertSee('Expense Analysis');
        $response->assertSee('Cash Flow');
    }
}
