<?php
/// file: app/Core/App.php

declare(strict_types=1);

namespace App\Core;

use App\Controllers\Admin\AuthController as AdminAuthController;
use App\Controllers\Admin\CareerController as AdminCareerController;
use App\Controllers\Admin\ContactAdminController;
use App\Controllers\Admin\DashboardController;
use App\Controllers\Admin\JournalAdminController;
use App\Controllers\Admin\MediaAdminController;
use App\Controllers\Admin\ProjectAdminController;
use App\Controllers\Admin\SeoAdminController;
use App\Controllers\Admin\ServiceAdminController;
use App\Controllers\Admin\SettingsController;
use App\Controllers\Api\ContactApiController;
use App\Controllers\Api\ProjectFilterController;
use App\Controllers\CareersController;
use App\Controllers\ContactController;
use App\Controllers\ErrorController;
use App\Controllers\HomeController;
use App\Controllers\JournalController;
use App\Controllers\LocaleController;
use App\Controllers\ProjectController;
use App\Controllers\ServiceController;
use App\Controllers\SitemapController;
use App\Controllers\StudioController;
use App\Controllers\WorkController;
use App\Middleware\AuthMiddleware;
use PDO;

final class App
{
    private Router $router;

    public function __construct(
        private readonly string $basePath,
        private readonly bool $debug
    ) {
        $this->router = new Router();
    }

    public function basePath(): string
    {
        return $this->basePath;
    }

    public function router(): Router
    {
        return $this->router;
    }

    public function debug(): bool
    {
        return $this->debug;
    }

    public function config(string $key, mixed $default = null): mixed
    {
        return Config::get($key, $default);
    }

    public function pdo(): PDO
    {
        return Database::pdo();
    }

    /**
     * @param class-string $class
     * @return object
     */
    public function make(string $class): object
    {
        return match ($class) {
            Auth::class => new Auth(),
            AuthMiddleware::class => new AuthMiddleware($this),
            HomeController::class => new HomeController($this),
            StudioController::class => new StudioController($this),
            WorkController::class => new WorkController($this),
            ProjectController::class => new ProjectController($this),
            ServiceController::class => new ServiceController($this),
            JournalController::class => new JournalController($this),
            ContactController::class => new ContactController($this),
            CareersController::class => new CareersController($this),
            ErrorController::class => new ErrorController($this),
            AdminAuthController::class => new AdminAuthController($this),
            DashboardController::class => new DashboardController($this),
            ProjectAdminController::class => new ProjectAdminController($this),
            JournalAdminController::class => new JournalAdminController($this),
            MediaAdminController::class => new MediaAdminController($this),
            ServiceAdminController::class => new ServiceAdminController($this),
            ContactAdminController::class => new ContactAdminController($this),
            SettingsController::class => new SettingsController($this),
            SeoAdminController::class => new SeoAdminController($this),
            AdminCareerController::class => new AdminCareerController($this),
            ContactApiController::class => new ContactApiController($this),
            ProjectFilterController::class => new ProjectFilterController($this),
            SitemapController::class => new SitemapController($this),
            LocaleController::class => new LocaleController($this),
            default => new $class($this),
        };
    }
}
