<?php

declare(strict_types=1);

use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use App\Support\Workspaces\WorkspaceContext;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('does not show the register-tenant CTA for readonly workspace members when there are no tenants', function (): void {
    $user = User::factory()->create();

    $workspace = Workspace::factory()->create();

    WorkspaceMembership::factory()->create([
        'workspace_id' => $workspace->getKey(),
        'user_id' => $user->getKey(),
        'role' => 'readonly',
    ]);

    $this->actingAs($user)
        ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
        ->get('/admin/choose-tenant')
        ->assertSuccessful()
        ->assertSee('No tenants available')
        ->assertDontSee('Register tenant');
});

it('does not show the register-tenant CTA for owner workspace members when there are no tenants', function (): void {
    $user = User::factory()->create();

    $workspace = Workspace::factory()->create();

    WorkspaceMembership::factory()->create([
        'workspace_id' => $workspace->getKey(),
        'user_id' => $user->getKey(),
        'role' => 'owner',
    ]);

    $this->actingAs($user)
        ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
        ->get('/admin/choose-tenant')
        ->assertSuccessful()
        ->assertSee('No tenants available')
        ->assertSee('Switch workspace')
        ->assertDontSee('Register tenant');
});
