<?php

namespace Tests\Feature\Integration;

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

class PermissionIntegrationTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed(RolesAndPermissionsSeeder::class);
    }

    public function test_bursar_can_access_accounting_routes(): void
    {
        $bursar = User::factory()->create();
        $bursar->assignRole('Bursar');

        $this->actingAs($bursar)
            ->get(route('accounting.journal.index'))
            ->assertOk();
    }

    public function test_teacher_cannot_access_finance_create_routes(): void
    {
        $teacher = User::factory()->create();
        $teacher->assignRole('Teacher');

        $this->actingAs($teacher)
            ->get(route('finance.invoices.create'))
            ->assertForbidden();
    }

    public function test_auditor_can_view_finance_but_not_create(): void
    {
        $auditor = User::factory()->create();
        $auditor->assignRole('Auditor');

        $this->actingAs($auditor)
            ->get(route('finance.invoices.index'))
            ->assertOk();

        $this->actingAs($auditor)
            ->get(route('finance.invoices.create'))
            ->assertForbidden();
    }

    public function test_teacher_cannot_access_extras_routes(): void
    {
        $teacher = User::factory()->create();
        $teacher->assignRole('Teacher');

        $this->actingAs($teacher)
            ->get(route('extras.messages.index'))
            ->assertForbidden();
    }

    public function test_administrator_can_access_extras_routes(): void
    {
        $admin = User::factory()->create();
        $admin->assignRole('Administrator');

        $this->actingAs($admin)
            ->get(route('extras.messages.index'))
            ->assertOk();
    }
}