<?php

declare(strict_types=1);

use App\Models\ManagedEnvironment;
use App\Support\Tenants\TenantLifecycle;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('normalizes canonical lifecycle values only', function (string $input, TenantLifecycle $expected): void {
    expect(TenantLifecycle::tryFromValue($input))->toBe($expected);
})->with([
    'draft' => ['draft', TenantLifecycle::Draft],
    'onboarding' => ['onboarding', TenantLifecycle::Onboarding],
    'active' => ['active', TenantLifecycle::Active],
    'archived' => ['archived', TenantLifecycle::Archived],
]);

it('returns null for non-canonical lifecycle aliases', function (): void {
    expect(TenantLifecycle::tryFromValue('pending'))->toBeNull()
        ->and(TenantLifecycle::tryFromValue('inactive'))->toBeNull();
});

it('derives archived lifecycle from soft-deleted tenants', function (): void {
    $tenant = ManagedEnvironment::factory()->archived()->create();

    expect(TenantLifecycle::fromTenant($tenant))->toBe(TenantLifecycle::Archived);
});
