<?php

namespace App\Listeners;

use App\Events\InvoiceGenerateEvent;
use App\Services\Helper\PdfGenerator;

class InvoiceGenerateListener
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(InvoiceGenerateEvent $event): void
    {
        $deposit = $event->deposit;

        PdfGenerator::makeInvoice('invoice.deposit', [
            'deposit' => $deposit->load('payment', 'user'),
        ], "deposit/$deposit->track.pdf");
    }
}
