<?php

namespace Tests\Unit\Services\Reimbursements;

use App\Services\Reimbursements\ReimbursementRecipientService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ReimbursementRecipientServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_recipient_options_include_staff_and_specials(): void
    {
        DB::table('users')->insert([
            [
                'id' => 1,
                'school_id' => 1,
                'firstname' => 'Admin',
                'lastname' => 'User',
                'cellphone' => '5555555555',
                'email' => 'admin@example.com',
                'address_street' => '123 Main',
                'city' => 'City',
                'state' => 'ST',
                'zip' => '12345',
                'accept_school_policy' => 1,
                'is_verified' => 1,
                'status' => 'Active',
                'is_suspended' => 0,
                'failed_attempts' => 0,
                'password' => bcrypt('secret'),
                'semester' => 'Fall',
                'school_year' => '2025-2026',
            ],
            [
                'id' => 2,
                'school_id' => 1,
                'firstname' => 'Parent',
                'lastname' => 'User',
                'cellphone' => '5555555555',
                'email' => 'parent@example.com',
                'address_street' => '123 Main',
                'city' => 'City',
                'state' => 'ST',
                'zip' => '12345',
                'accept_school_policy' => 1,
                'is_verified' => 1,
                'status' => 'Active',
                'is_suspended' => 0,
                'failed_attempts' => 0,
                'password' => bcrypt('secret'),
                'semester' => 'Fall',
                'school_year' => '2025-2026',
            ],
        ]);

        DB::table('roles')->insert([
            ['id' => 1, 'name' => 'admin'],
            ['id' => 2, 'name' => 'parent'],
        ]);

        DB::table('user_roles')->insert([
            ['user_id' => 1, 'role_id' => 1],
            ['user_id' => 2, 'role_id' => 2],
        ]);

        $service = new ReimbursementRecipientService();
        $recipients = $service->recipientOptions();

        $ids = array_map(static fn ($row) => (int) ($row['id'] ?? 0), $recipients);

        $this->assertContains(1, $ids);
        $this->assertNotContains(2, $ids);
        $this->assertContains(990001, $ids);
        $this->assertContains(990002, $ids);
    }
}
