<?php

namespace Tests\Unit\Services\Roles;

use App\Services\Roles\RoleDashboardService;
use App\Services\Roles\RoleSwitchService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class RoleSwitchServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_get_user_role_names_returns_roles(): void
    {
        $userId = DB::table('users')->insertGetId([
            'firstname' => 'Admin',
            'lastname' => 'User',
            'cellphone' => '9999999999',
            'email' => 'switch.unit@example.com',
            'address_street' => '123 Street',
            'city' => 'City',
            'state' => 'ST',
            'zip' => '12345',
            'accept_school_policy' => 1,
            'password' => bcrypt('password'),
            'user_type' => 'primary',
            'semester' => 'Fall',
            'school_year' => '2025-2026',
            'status' => 'Active',
        ]);

        $roleId = DB::table('roles')->insertGetId([
            'name' => 'admin',
            'slug' => 'admin',
            'description' => 'Admin',
            'dashboard_route' => 'administrator/administratordashboard',
            'priority' => 1,
            'is_active' => 1,
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        DB::table('user_roles')->insert([
            'user_id' => $userId,
            'role_id' => $roleId,
        ]);

        $service = new RoleSwitchService(new RoleDashboardService());
        $roles = $service->getUserRoleNames($userId);

        $this->assertSame(['admin'], $roles);
    }
}
