<?php

function goals_openapi_content_or_skip(): string
{
    $candidates = [];
    for ($depth = 1; $depth <= 8; $depth++) {
        $candidates[] = dirname(__DIR__, $depth) . DIRECTORY_SEPARATOR . 'openapi.yaml';
    }

    $cwd = getcwd();
    if (is_string($cwd) && $cwd !== '') {
        $candidates[] = $cwd . DIRECTORY_SEPARATOR . 'openapi.yaml';
        $candidates[] = dirname($cwd) . DIRECTORY_SEPARATOR . 'openapi.yaml';
    }

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

    test()->markTestSkipped('openapi.yaml is not available in this runtime environment.');
}

it('documents advanced goals target duration fields in openapi', function (): void {
    $content = goals_openapi_content_or_skip();

    expect($content)->toContain('GoalsCriteria:');
    expect($content)->toContain('target_duration:');
    expect($content)->toContain('target_duration_every:');
    expect($content)->toContain('enum: [ENTIRE_DURATION, WEEKS, MONTHS, YEARS]');
    expect($content)->toContain('targetDuration');
    expect($content)->toContain('targetDurationEvery');
});
