<?php

namespace Tests\Feature;

use App\Enums\CertificateStatus;
use App\Enums\UserRole;
use App\Models\Participant;
use App\Models\User;
use App\Services\IcNumberService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminAuthTest extends TestCase
{
    use RefreshDatabase;

    public function test_admin_can_login(): void
    {
        $user = User::factory()->create([
            'email' => 'admin@test.com',
            'password' => 'password123',
            'role' => UserRole::SuperAdmin,
            'is_active' => true,
        ]);

        $response = $this->post('/admin/login', [
            'email' => 'admin@test.com',
            'password' => 'password123',
        ]);

        $response->assertRedirect(route('admin.dashboard'));
        $this->assertAuthenticatedAs($user);
    }

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

    public function test_inactive_admin_cannot_access(): void
    {
        $user = User::factory()->create([
            'role' => UserRole::Admin,
            'is_active' => false,
        ]);

        $this->actingAs($user)->get('/admin/dashboard')->assertRedirect('/admin/login');
    }
}
