<?php

declare(strict_types=1);

namespace ImovelZapAi\Documents\Infrastructure\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use ImovelZapAi\Documents\Application\Actions\AddDocumentCommentAction;
use ImovelZapAi\Documents\Application\Actions\CreateDocumentAction;
use ImovelZapAi\Documents\Application\Actions\CreateDocumentVersionAction;
use ImovelZapAi\Documents\Application\Actions\DecideDocumentAction;
use ImovelZapAi\Documents\Application\Actions\ExpireDocumentAction;
use ImovelZapAi\Documents\Application\Actions\RecordDocumentViewAction;
use ImovelZapAi\Documents\Application\Actions\SaveDocumentTemplateAction;
use ImovelZapAi\Documents\Application\Actions\ShareDocumentAction;
use ImovelZapAi\Documents\Application\Queries\GetDocumentDashboardQuery;
use ImovelZapAi\Documents\Application\Queries\ListDocumentsQuery;
use ImovelZapAi\Documents\Application\Queries\ListDocumentTemplatesQuery;
use ImovelZapAi\Documents\Application\Services\DefaultDocumentTemplateSeeder;
use ImovelZapAi\Documents\Application\Services\DocumentHistoryWriter;
use ImovelZapAi\Documents\Application\Services\DocumentPdfGenerator;
use ImovelZapAi\Documents\Application\Services\DocumentShareTokenService;
use ImovelZapAi\Documents\Application\Services\DocumentVariableCatalog;
use ImovelZapAi\Documents\Application\Services\DocumentVariableResolver;

class DocumentsServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(config_path('documents.php'), 'documents');
        $this->app->singleton(DocumentHistoryWriter::class);
        $this->app->singleton(DocumentShareTokenService::class);
        $this->app->singleton(DocumentVariableCatalog::class);
        $this->app->singleton(DocumentVariableResolver::class);
        $this->app->singleton(DocumentPdfGenerator::class);
        $this->app->singleton(DefaultDocumentTemplateSeeder::class);
        $this->app->singleton(CreateDocumentAction::class);
        $this->app->singleton(CreateDocumentVersionAction::class);
        $this->app->singleton(ShareDocumentAction::class);
        $this->app->singleton(RecordDocumentViewAction::class);
        $this->app->singleton(DecideDocumentAction::class);
        $this->app->singleton(SaveDocumentTemplateAction::class);
        $this->app->singleton(ExpireDocumentAction::class);
        $this->app->singleton(AddDocumentCommentAction::class);
        $this->app->singleton(ListDocumentsQuery::class);
        $this->app->singleton(ListDocumentTemplatesQuery::class);
        $this->app->singleton(GetDocumentDashboardQuery::class);
    }

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

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