<?php

namespace Tests\Feature;

use App\Models\Course;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Tests\Traits\WithTestAuth;

class AdminCourseTest extends TestCase
{
    use RefreshDatabase;
    use WithTestAuth;

    private $admin;

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

        // Use helper to create admin with granular permissions
        // Note: If tests fail 403, we might need to fallback to empty array (super_admin)
        // But let's try strict first as requested.

        $permissions = [
            'ViewAny:Course',
            'Create:Course',
            'page_Dashboard', // Assuming this or panel_user grants panel access
        ];

        $this->admin = $this->createAdminUser($permissions);
    }

    public function test_admin_can_access_courses_page(): void
    {
        $this->actingAs($this->admin)
            ->get('/admin/courses')
            ->assertStatus(200);
    }

    public function test_admin_can_create_course(): void
    {
        $this->actingAs($this->admin)
            ->get('/admin/courses/create')
            ->assertStatus(200);

        $course = Course::factory()->create(['title' => 'Visible Course']);

        $this->actingAs($this->admin)
            ->get('/admin/courses')
            ->assertSee('Visible Course');
    }
}
