<?php

namespace Console;

use App\ServiceProviders\AppServiceProvider;
use App\ServiceProviders\SettingsServiceProvider;
use Openguru\OpenCartFramework\Application;
use Openguru\OpenCartFramework\Cache\CacheServiceProvider;
use Openguru\OpenCartFramework\ImageTool\ImageToolServiceProvider;
use Openguru\OpenCartFramework\QueryBuilder\QueryBuilderServiceProvider;
use Openguru\OpenCartFramework\Scheduler\SchedulerServiceProvider;
use Openguru\OpenCartFramework\Support\Arr;
use Openguru\OpenCartFramework\TeleCartPulse\TeleCartPulseServiceProvider;
use Openguru\OpenCartFramework\Telegram\TelegramServiceProvider;

class ApplicationFactory
{
    public static function create(array $settings): Application
    {
        $defaultConfig = require __DIR__ . '/../configs/app.php';

        $merged = Arr::mergeArraysRecursively($defaultConfig, $settings);

        return (new Application($merged))
            ->withServiceProviders([
                SettingsServiceProvider::class,
                QueryBuilderServiceProvider::class,
                AppServiceProvider::class,
                CacheServiceProvider::class,
                TelegramServiceProvider::class,
                TeleCartPulseServiceProvider::class,
                SchedulerServiceProvider::class,
                ImageToolServiceProvider::class,
            ]);
    }
}
