<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Support\Print\DberpDocumentPrintRegistry;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

final class DocumentPrintController extends Controller
{
    public function __construct(
        private readonly DberpDocumentPrintRegistry $registry,
    ) {}

    public function __invoke(Request $request, string $documentKey, int|string $record): View
    {
        $presenter = $this->registry->resolve($documentKey);

        abort_unless($presenter->userCanPrint($request->user()), 403);

        $viewData = $presenter->prepareViewData($record);

        return view($viewData['view'], $viewData);
    }
}
