<?php

declare(strict_types=1);

namespace App\Config;

use Illuminate\Database\Capsule\Manager as Capsule;
use Psr\Container\ContainerInterface;

final class Container
{
    private static ?Capsule $capsule = null;

    public static function boot(): void
    {
        if (self::$capsule !== null) {
            return;
        }

        self::$capsule = new Capsule();

        self::$capsule->addConnection([
            'driver' => 'pgsql',
            'host' => '127.0.0.1',
            'port' => '5433',
            'database' => 'fahrschultermin',
            'username' => 'fahrschultermin_api',
            'password' => 'X9wL3pN7kRtHvMbZs4cGfYu2Dj6qAe8t',
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ]);

        self::$capsule->setAsGlobal();
        self::$capsule->bootEloquent();
    }

    public static function build(): ContainerInterface
    {
        self::boot();

        $builder = new \DI\ContainerBuilder();

        $builder->addDefinitions([
            'jwt.secret' => 'your-256-bit-secret-change-in-production',
            'config' => [
                'frontend_url' => 'https://fahrschultermin.de',
                'api_base_url' => 'https://api.fahrschultermin.de',
                'session_name' => 'drive_time_session',
            ],
        ]);

        return $builder->build();
    }
}