<?php

namespace Tests\Feature;

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

class DashboardTest extends TestCase
{
    use RefreshDatabase;

    public function test_guest_redirected_to_login(): void
    {
        $this->get('/')->assertRedirect('/login');
    }

    public function test_trader_can_view_dashboard(): void
    {
        $user = User::factory()->create(['role' => 'user', 'email_verified_at' => now()]);

        $this->actingAs($user)->get('/dashboard')->assertOk();
    }

    public function test_admin_can_view_admin_panel(): void
    {
        $admin = User::factory()->create(['role' => 'admin', 'email_verified_at' => now()]);

        $this->actingAs($admin)->get('/admin')->assertOk();
    }

    public function test_user_cannot_view_admin_panel(): void
    {
        $user = User::factory()->create(['role' => 'user', 'email_verified_at' => now()]);

        $this->actingAs($user)->get('/admin')->assertForbidden();
    }

    public function test_market_sync_requires_admin_feed(): void
    {
        $this->artisan('market:sync')->assertFailed();
    }
}
