<?php

declare(strict_types=1);

use App\Http\Controllers\ImportController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Import
|--------------------------------------------------------------------------
|
| Bulk-onboarding for the asset register. Open to every signed-in user,
| matching every other module — there is nothing here a regular user
| shouldn't be able to do.
|
| `create` and `template/{module}` are static-ish paths and must be
| registered before the `{batch}` group below, for the same reason
| `assets.php` registers `export` before its `{asset}` resource routes:
| Laravel matches in registration order, and a wildcard registered first
| would swallow "create" or "template" as if they were a batch ID.
|
*/

Route::get('imports', [ImportController::class, 'index'])->name('imports.index');
Route::get('imports/create', [ImportController::class, 'create'])->name('imports.create');
Route::get('imports/template/{module}', [ImportController::class, 'template'])->name('imports.template');
Route::post('imports', [ImportController::class, 'store'])->name('imports.store');

Route::prefix('imports/{batch}')->name('imports.')->group(function (): void {
    Route::get('preview', [ImportController::class, 'preview'])->name('preview');
    Route::post('confirm', [ImportController::class, 'confirm'])->name('confirm');
    Route::get('errors', [ImportController::class, 'errors'])->name('errors');
    Route::get('documents-report', [ImportController::class, 'documentsReport'])->name('documents-report');
    Route::get('/', [ImportController::class, 'show'])->name('show');
});
