<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use App\Framework\Filesystem\FileStorage;

// Create temp directory
$testDir = sys_get_temp_dir() . '/list_test_' . uniqid();
mkdir($testDir, 0777, true);

echo "Test directory: $testDir\n";

// Create FileStorage
$storage = new FileStorage(basePath: $testDir);

// Create some files
$storage->put('listable/file1.txt', 'content1');
$storage->put('listable/file2.txt', 'content2');
$storage->put('listable/file3.txt', 'content3');

echo "\nFiles created\n";

// List directory
$contents = $storage->listDirectory('listable');

echo "\nDirectory contents:\n";
echo "Type: " . gettype($contents) . "\n";
echo "Count: " . count($contents) . "\n";
echo "Contents: " . print_r($contents, true) . "\n";

echo "\nArray values:\n";
print_r(array_values($contents));

// Cleanup
function deleteDirectoryRecursive(string $dir): void
{
    if (!is_dir($dir)) {
        return;
    }

    $files = array_diff(scandir($dir), ['.', '..']);

    foreach ($files as $file) {
        $path = $dir . '/' . $file;
        if (is_dir($path)) {
            deleteDirectoryRecursive($path);
        } else {
            unlink($path);
        }
    }

    rmdir($dir);
}

deleteDirectoryRecursive($testDir);

echo "\nCleanup done\n";
