<?php

use MintyPHP\Module\ApiDocs\ApiDocsAuthorizationPolicy;
use MintyPHP\Support\Guard;

define('MINTY_ALLOW_OUTPUT', true);

Guard::requireLogin();
Guard::requireAbilityOrForbidden(ApiDocsAuthorizationPolicy::ABILITY_VIEW);

$specPath = defined('APP_ROOT') ? APP_ROOT . '/docs/openapi.yaml' : dirname(__DIR__, 4) . '/docs/openapi.yaml';

if (!is_file($specPath)) {
    http_response_code(404);
    return;
}

if (!is_readable($specPath)) {
    http_response_code(500);
    return;
}

header('Content-Type: application/yaml; charset=utf-8');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: private, max-age=60');
$bytes = @readfile($specPath);
if ($bytes === false) {
    http_response_code(500);
}
