<?php

declare(strict_types=1);

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

use App\Framework\Core\ContainerBootstrapper;
use App\Framework\OAuth\Providers\SpotifyProvider;
use App\Framework\Config\Environment;

try {
    $envPath = __DIR__ . '/.env';
    if (!file_exists($envPath)) {
        throw new \RuntimeException(".env file not found at: {$envPath}");
    }

    $envVars = parse_ini_file($envPath);
    if ($envVars === false) {
        throw new \RuntimeException("Failed to parse .env file");
    }

    $env = new Environment($envVars);

    echo "Environment loaded\n";
    echo "SPOTIFY_CLIENT_ID: " . $env->get(\App\Framework\Config\EnvKey::fromString('SPOTIFY_CLIENT_ID'), 'NOT SET') . "\n";
    echo "SPOTIFY_CLIENT_SECRET: " . $env->get(\App\Framework\Config\EnvKey::fromString('SPOTIFY_CLIENT_SECRET'), 'NOT SET') . "\n";

    $containerBootstrapper = new ContainerBootstrapper($env);
    $container = $containerBootstrapper->bootstrap();

    echo "Container bootstrapped\n";

    $spotifyProvider = $container->get(SpotifyProvider::class);

    echo "✅ SpotifyProvider successfully resolved from container\n";
    echo "Provider name: " . $spotifyProvider->getName() . "\n";

} catch (\Exception $e) {
    echo "❌ Error: " . $e->getMessage() . "\n";
    echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
    echo "\nStack trace:\n";
    echo $e->getTraceAsString() . "\n";
}
