<?php
declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

use Crawl\Repositories\CrawlPageRepository;
use Crawl\Repositories\CrawlLinkRepository;

function assertTrue(bool $condition, string $message): void
{
    if (!$condition) {
        throw new RuntimeException($message);
    }
}

try {
    $pageRepo = new CrawlPageRepository();
    $result = $pageRepo->paginated(-1, [], 25, 0, 'url', 'ASC');
    assertTrue(is_array($result), 'Expected paginated result to be an array');
    assertTrue(array_key_exists('rows', $result) && array_key_exists('total', $result), 'Result should include rows and total');
    assertTrue(is_int($result['total']), 'Expected total to be integer');

    $linkRepo = new CrawlLinkRepository();
    $links = $linkRepo->tabData(-1, 'outlinks', 10, 0);
    assertTrue(is_array($links), 'Expected tabData to return an array');

    echo "Repository smoke tests passed.\n";
} catch (Throwable $e) {
    fwrite(STDERR, 'Repository test failed: ' . $e->getMessage() . "\n");
    exit(1);
}
