<?php

declare(strict_types=1);

namespace ImovelZapAi\Importing\Infrastructure\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use ImovelZapAi\Importing\Application\Actions\AnalyzeImportAction;
use ImovelZapAi\Importing\Application\Actions\ConfirmImportAction;
use ImovelZapAi\Importing\Application\Actions\ExecuteImportAction;
use ImovelZapAi\Importing\Application\Actions\RetryImportAction;
use ImovelZapAi\Importing\Application\Actions\UpdateImportMappingAction;
use ImovelZapAi\Importing\Application\Actions\UploadImportAction;
use ImovelZapAi\Importing\Application\Ports\PropertyImportWriterInterface;
use ImovelZapAi\Importing\Application\Ports\VrSyncParserInterface;
use ImovelZapAi\Importing\Application\Queries\GetImportDashboardQuery;
use ImovelZapAi\Importing\Application\Queries\GetImportReportQuery;
use ImovelZapAi\Importing\Application\Queries\ListImportsQuery;
use ImovelZapAi\Importing\Application\Services\ImportFileStorage;
use ImovelZapAi\Importing\Application\Services\ImportListingValidator;
use ImovelZapAi\Importing\Application\Services\ImportLogWriter;
use ImovelZapAi\Importing\Application\Services\ImportMappingResolver;
use ImovelZapAi\Importing\Application\Services\SafeRemoteMediaDownloader;
use ImovelZapAi\Importing\Application\Services\XmlReaderVrSyncParser;
use ImovelZapAi\Importing\Infrastructure\Persistence\EloquentPropertyImportWriter;

class ImportingServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(config_path('importing.php'), 'importing');

        $this->app->singleton(ImportFileStorage::class);
        $this->app->singleton(ImportLogWriter::class);
        $this->app->singleton(ImportListingValidator::class);
        $this->app->singleton(ImportMappingResolver::class);
        $this->app->singleton(SafeRemoteMediaDownloader::class);
        $this->app->singleton(VrSyncParserInterface::class, XmlReaderVrSyncParser::class);
        $this->app->singleton(PropertyImportWriterInterface::class, EloquentPropertyImportWriter::class);

        $this->app->singleton(UploadImportAction::class);
        $this->app->singleton(AnalyzeImportAction::class);
        $this->app->singleton(UpdateImportMappingAction::class);
        $this->app->singleton(ConfirmImportAction::class);
        $this->app->singleton(ExecuteImportAction::class);
        $this->app->singleton(RetryImportAction::class);
        $this->app->singleton(GetImportReportQuery::class);
        $this->app->singleton(GetImportDashboardQuery::class);
        $this->app->singleton(ListImportsQuery::class);
    }

    public function boot(): void
    {
        View::addNamespace('importing', resource_path('views/importing'));

        Route::middleware('web')
            ->group(__DIR__.'/../../Presentation/Http/routes/web.php');

        Route::middleware('api')
            ->prefix('api/v1')
            ->group(__DIR__.'/../../Presentation/Http/routes/api.php');
    }
}
