<?php

declare(strict_types=1);

use App\Support\Tenants\TenantInteractionLane;
use App\Support\Tenants\TenantLifecycle;
use App\Support\Tenants\TenantOperabilityOutcome;
use App\Support\Tenants\TenantOperabilityQuestion;
use App\Support\Tenants\TenantOperabilityReasonCode;

it('builds allowed outcomes with stable defaults', function (): void {
    $outcome = TenantOperabilityOutcome::allow(
        question: TenantOperabilityQuestion::AdministrativeDiscoverability,
        lifecycle: TenantLifecycle::Archived,
        lane: TenantInteractionLane::AdministrativeManagement,
        metadata: ['selected_tenant_id' => 123],
    );

    expect($outcome->allowed)->toBeTrue()
        ->and($outcome->discoverable)->toBeTrue()
        ->and($outcome->reasonCode)->toBeNull()
        ->and($outcome->metadata)->toBe(['selected_tenant_id' => 123]);
});

it('distinguishes capability and lifecycle denials', function (): void {
    $capabilityOutcome = TenantOperabilityOutcome::deny(
        question: TenantOperabilityQuestion::ArchiveEligibility,
        lifecycle: TenantLifecycle::Active,
        lane: TenantInteractionLane::AdministrativeManagement,
        reasonCode: TenantOperabilityReasonCode::MissingCapability,
        requiredCapability: 'tenant.manage',
    );

    $lifecycleOutcome = TenantOperabilityOutcome::deny(
        question: TenantOperabilityQuestion::SelectorEligibility,
        lifecycle: TenantLifecycle::Onboarding,
        lane: TenantInteractionLane::StandardActiveOperating,
        reasonCode: TenantOperabilityReasonCode::SelectorIneligibleLifecycle,
    );

    expect($capabilityOutcome->isDeniedForCapability())->toBeTrue()
        ->and($capabilityOutcome->isDeniedForLifecycle())->toBeFalse()
        ->and($lifecycleOutcome->isDeniedForCapability())->toBeFalse()
        ->and($lifecycleOutcome->isDeniedForLifecycle())->toBeTrue();
});
