<?php

function department_weather_targets_openapi_content_or_skip(): string
{
    $candidates = [WD . '/openapi.yaml'];
    for ($depth = 1; $depth <= 8; $depth++) {
        $candidates[] = dirname(WD, $depth) . '/openapi.yaml';
    }
    $cwd = getcwd();
    if (is_string($cwd) && $cwd !== '') {
        $candidates[] = $cwd . DIRECTORY_SEPARATOR . 'openapi.yaml';
        $candidates[] = dirname($cwd) . DIRECTORY_SEPARATOR . 'openapi.yaml';
    }
    $candidates = array_values(array_unique($candidates));

    foreach ($candidates as $candidate) {
        if (!is_file($candidate)) {
            continue;
        }
        $content = file_get_contents($candidate);
        if ($content !== false) {
            return $content;
        }
    }

    test()->markTestSkipped('openapi.yaml is not mounted in this test container.');
}

it('documents department weather target endpoints and reusable schemas in openapi', function (): void {
    $content = department_weather_targets_openapi_content_or_skip();

    expect($content)->toContain('/departments/weather/targets:');
    expect($content)->toContain('operationId: getDepartmentWeatherTargets');
    expect($content)->toContain('operationId: upsertDepartmentWeatherTarget');
    expect($content)->toContain('DepartmentWeatherTarget:');
    expect($content)->toContain('DepartmentWeatherTargetsResponse:');
    expect($content)->toContain('DepartmentWeatherTargetUpsertRequest:');
});

it('documents unknown weather status behavior when targets are missing', function (): void {
    $content = department_weather_targets_openapi_content_or_skip();

    expect($content)->toContain('DepartmentWeatherStatus:');
    expect($content)->toContain('missing department weather targets');
    expect($content)->toContain('enum: [unknown, healthy, degraded, unhealthy]');
});
