<?php
require_once __DIR__ . '/security.php';

if (defined('TENANT_URL') && !empty(TENANT_URL)) {
    $_REQUEST['tenant'] = TENANT_URL;
}

if (!defined('CONFIG_LOADED')) {
    $tenant = enrep_tenant_segment();
    if ($tenant !== '' && is_file('../../' . $tenant . '/config.php')) {
        require_once '../../' . $tenant . '/config.php';
    } elseif (is_file('/config.php')) {
        require_once '/config.php';
    }
}

enrep_require_admin();

$manual = __DIR__ . '/api/v1/EnRep_Client_API_Manual.md';
if (!is_file($manual)) {
    enrep_fail(404, 'API manual not found');
}

header('Content-Type: text/markdown; charset=utf-8');
header('Content-Disposition: attachment; filename="EnRep_Client_API_Manual.md"');
header('Content-Length: ' . filesize($manual));
readfile($manual);
exit;
