<?php

namespace Openguru\OpenCartFramework\MaintenanceTasks;

use Openguru\OpenCartFramework\Cache\CacheInterface;
use Openguru\OpenCartFramework\Container\Container;
use Openguru\OpenCartFramework\Container\ServiceProvider;
use Psr\Log\LoggerInterface;
use Openguru\OpenCartFramework\Migrations\MigratorService;

class MaintenanceTasksServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->container->singleton(MaintenanceTasksService::class, function (Container $container) {
            $config = require configs_path('maintenance.php');
            $classes = $config['tasks'];
            $tasks = array_map(static fn(string $class) => static fn() => $container->get($class), $classes);

            return new MaintenanceTasksService(
                $container->get(MigratorService::class),
                $container->get(LoggerInterface::class),
                $container->get(CacheInterface::class),
                $tasks,
            );
        });
    }
}
