<?php

namespace Mtc\Modules\BlockRegistry\Providers;

use Illuminate\Support\ServiceProvider;
use Mtc\Modules\BlockRegistry\Services\BlockRegistryService;
use Mtc\Modules\BlockRegistry\Services\TemplateBlockService;
use Mtc\Modules\BlockRegistry\Services\EntityBlockService;
use Mtc\Modules\BlockRegistry\Services\ImageProcessingService;
use Mtc\Modules\BlockRegistry\Services\BlockTemplateService;
use Mtc\Modules\BlockRegistry\Services\BlockSyncService;
use Mtc\Modules\BlockRegistry\Console\Commands\BlocksExportCommand;
use Mtc\Modules\BlockRegistry\Console\Commands\BlocksImportCommand;
use Mtc\Modules\BlockRegistry\Console\Commands\BlocksDiffCommand;
use Mtc\Modules\BlockRegistry\Console\Commands\BlocksRegenerateImagesCommand;

class BlockRegistryServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        $this->app->singleton(BlockRegistryService::class);

        $this->app->singleton(TemplateBlockService::class);
        $this->app->singleton(EntityBlockService::class);
        $this->app->singleton(ImageProcessingService::class);
        $this->app->singleton(BlockTemplateService::class);
        $this->app->singleton(BlockSyncService::class);
    }

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        $this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

        if ($this->app->runningInConsole()) {
            $this->commands([
                BlocksExportCommand::class,
                BlocksImportCommand::class,
                BlocksDiffCommand::class,
                BlocksRegenerateImagesCommand::class,
            ]);
        }
    }
}
