<?php

namespace App\Domains\Rechnung\Controllers;

use App\Domains\Rechnung\Actions\GeneratePdf\GeneratePdfCommand;
use App\Domains\Rechnung\Actions\GeneratePdf\GeneratePdfRequest;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class GeneratePdfController
{
    public function __invoke(Request $request): Response
    {
        $pdfRequest = GeneratePdfRequest::fromArray($request->all());
        $command    = new GeneratePdfCommand($pdfRequest);
        $result     = $command->execute();

        return response($result->pdfContent, 200, [
            'Content-Type'        => 'application/pdf',
            'Content-Disposition' => 'inline; filename="' . $result->filename . '"',
        ]);
    }
}
