<?php

namespace Tests\Feature;

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

class RoleAccessTest extends TestCase
{
    use RefreshDatabase;

    public function test_security_cannot_reach_users_page(): void
    {
        $site = Site::factory()->create();
        $security = User::factory()->security()->create(['site_id' => $site->id]);

        $response = $this->actingAs($security)->get('/users');
        $response->assertForbidden();
    }

    public function test_security_cannot_reach_employees_page(): void
    {
        $site = Site::factory()->create();
        $security = User::factory()->security()->create(['site_id' => $site->id]);

        $response = $this->actingAs($security)->get('/employees');
        $response->assertForbidden();
    }

    public function test_hr_cannot_reach_devices_page(): void
    {
        $hr = User::factory()->hr()->create();

        $response = $this->actingAs($hr)->get('/devices');
        $response->assertForbidden();
    }

    public function test_hr_cannot_reach_users_page(): void
    {
        $hr = User::factory()->hr()->create();

        $response = $this->actingAs($hr)->get('/users');
        $response->assertForbidden();
    }

    public function test_admin_can_reach_all_pages(): void
    {
        $admin = User::factory()->admin()->create();

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

    public function test_security_can_reach_dashboard_and_manual_entry(): void
    {
        $site = Site::factory()->create();
        $security = User::factory()->security()->create(['site_id' => $site->id]);

        $this->actingAs($security)->get('/dashboard')->assertOk();
        $this->actingAs($security)->get('/manual-entry')->assertOk();
    }
}
