<?php

if (PHP_SAPI !== 'cli') {
    http_response_code(403);
    exit('CLI only');
}

require_once __DIR__ . '/../core/config.php';

$checks = [
    'DB_HOST' => DB_HOST ?? '',
    'DB_NAME' => DB_NAME ?? '',
    'DB_USER' => DB_USER ?? '',
    'DB_PASS' => DB_PASS ?? '',
    'GOOGLE_MAPS_API_KEY' => GOOGLE_MAPS_API_KEY ?? '',
    'GOOGLE_CLIENT_ID' => GOOGLE_CLIENT_ID ?? '',
    'GOOGLE_CLIENT_SECRET' => GOOGLE_CLIENT_SECRET ?? '',
    'GOOGLE_ALLOWED_DOMAIN' => GOOGLE_ALLOWED_DOMAIN ?? '',
    'FACTO_API_BASE_URL' => FACTO_API_BASE_URL ?? '',
    'FACTO_CLIENT_ID' => FACTO_CLIENT_ID ?? '',
    'FACTO_CLIENT_SECRET' => FACTO_CLIENT_SECRET ?? '',
    'FACTO_USERNAME' => FACTO_USERNAME ?? '',
    'FACTO_PASSWORD' => FACTO_PASSWORD ?? '',
];

$missing = [];

echo "ICYLAB private config check\n";
echo "===========================\n";

foreach ($checks as $name => $value) {
    $isSet = trim((string) $value) !== '';
    echo str_pad($name, 28) . ($isSet ? "OK\n" : "MISSING\n");
    if (!$isSet) {
        $missing[] = $name;
    }
}

if ($missing) {
    echo "\nMissing required values: " . implode(', ', $missing) . "\n";
    exit(1);
}

echo "\nAll required private config values are present.\n";
exit(0);
