<?php

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;

class PlatformSuperAdminTenantAccessTest extends TestCase
{
    use RefreshDatabase;

    public function test_platform_superadmin_cannot_open_tenant_employee_list(): void
    {
        $superAdmin = User::factory()->create([
            'is_superadmin' => true,
            'company_id' => null,
            'allow_login' => true,
        ]);

        $response = $this->actingAs($superAdmin)->get(route('employees.index'));

        $response->assertRedirect(route('superadmin.dashboard'));
    }

    public function test_platform_superadmin_cannot_use_tenant_api(): void
    {
        $superAdmin = User::factory()->create([
            'is_superadmin' => true,
            'company_id' => null,
        ]);

        Sanctum::actingAs($superAdmin);

        $response = $this->getJson('/api/employees');

        $response->assertStatus(403);
    }

    public function test_tenant_user_can_open_employee_list(): void
    {
        $employee = User::factory()->create([
            'is_superadmin' => false,
            'company_id' => 1,
            'allow_login' => true,
        ]);

        $response = $this->actingAs($employee)->get(route('employees.index'));

        $response->assertOk();
    }
}
