<?php

namespace Tests\Feature;

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

class ParentPortalTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        Role::create(['name' => 'siswa', 'label' => 'Siswa']);
    }

    public function test_unauthenticated_parent_can_access_portal_via_token(): void
    {
        $student = User::factory()->create([
            'role_id' => 1,
            'name' => 'Doni Saputra',
            'parent_token' => 'unique-token-doni-123',
            'class_name' => 'X TKJ 1',
        ]);

        AttendanceRecord::create([
            'user_id' => $student->id,
            'date' => now()->toDateString(),
            'check_in' => '06:50:00',
            'status' => 'Hadir',
        ]);

        $response = $this->get(route('parent.portal', 'unique-token-doni-123'));
        $response->assertStatus(200);
        $response->assertSee('Doni Saputra');
        $response->assertSee('X TKJ 1');
        $response->assertSee('Hadir');
    }
}
