<?php

declare(strict_types=1);

use App\Support\CustomerHealth\CustomerHealthDimensionCatalog;

it('exposes the fixed first-slice health dimensions and their time basis', function (): void {
    $catalog = new CustomerHealthDimensionCatalog();

    expect($catalog->names())->toBe([
        CustomerHealthDimensionCatalog::ONBOARDING_READINESS,
        CustomerHealthDimensionCatalog::PROVIDER_CONNECTION_HEALTH,
        CustomerHealthDimensionCatalog::OPERATIONAL_STABILITY,
        CustomerHealthDimensionCatalog::GOVERNANCE_PRESSURE,
        CustomerHealthDimensionCatalog::REVIEW_PACK_READINESS,
        CustomerHealthDimensionCatalog::ENGAGEMENT_FRESHNESS,
    ])->and($catalog->visibleDimensions())->toBe([
        CustomerHealthDimensionCatalog::ONBOARDING_READINESS => 'Onboarding readiness',
        CustomerHealthDimensionCatalog::PROVIDER_CONNECTION_HEALTH => 'Provider connection health',
        CustomerHealthDimensionCatalog::OPERATIONAL_STABILITY => 'Operational stability',
        CustomerHealthDimensionCatalog::GOVERNANCE_PRESSURE => 'Governance pressure',
        CustomerHealthDimensionCatalog::REVIEW_PACK_READINESS => 'Review-pack readiness',
        CustomerHealthDimensionCatalog::ENGAGEMENT_FRESHNESS => 'Engagement freshness',
    ])->and($catalog->isWindowed(CustomerHealthDimensionCatalog::OPERATIONAL_STABILITY))->toBeTrue()
        ->and($catalog->isWindowed(CustomerHealthDimensionCatalog::REVIEW_PACK_READINESS))->toBeTrue()
        ->and($catalog->isWindowed(CustomerHealthDimensionCatalog::ENGAGEMENT_FRESHNESS))->toBeTrue()
        ->and($catalog->isWindowed(CustomerHealthDimensionCatalog::ONBOARDING_READINESS))->toBeFalse()
        ->and($catalog->isWindowed(CustomerHealthDimensionCatalog::PROVIDER_CONNECTION_HEALTH))->toBeFalse()
        ->and($catalog->isWindowed(CustomerHealthDimensionCatalog::GOVERNANCE_PRESSURE))->toBeFalse();
});

it('resolves the overall health level using the fixed severity precedence', function (): void {
    $catalog = new CustomerHealthDimensionCatalog();

    expect($catalog->resolveOverallLevel(['ok', 'unknown']))->toBe('unknown')
        ->and($catalog->resolveOverallLevel(['ok', 'warn', 'unknown']))->toBe('warn')
        ->and($catalog->resolveOverallLevel(['critical', 'ok']))->toBe('critical')
        ->and($catalog->resolveOverallLevel(['ok']))->toBe('ok');
});

it('rejects unknown customer health dimensions', function (): void {
    $catalog = new CustomerHealthDimensionCatalog();

    expect(fn () => $catalog->definition('customer_health.unknown'))
        ->toThrow(InvalidArgumentException::class, 'Unknown customer health dimension');
});