<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Offers\Services;

use Barryvdh\DomPDF\Facades\Pdf;
use Maestro\Core\Modules\Offers\Models\Offer;
use Symfony\Component\HttpFoundation\Response;

final class OfferPdfExporter
{
    public static function downloadResponse(Offer $offer): Response
    {
        $payload = OfferDocumentBuilder::build($offer);

        return Pdf::loadView('maestro-core::offers.document', ['doc' => $payload])
            ->setPaper('a4')
            ->setOption('isRemoteEnabled', true)
            ->download(sprintf('offer-%s.pdf', preg_replace('/[^a-zA-Z0-9._-]/', '_', $offer->offer_number)));
    }
}
