<?php

declare(strict_types=1);

namespace App\Jobs\Eboekhouden;

use App\Models\Merchant;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

final class GenerateInvoices implements ShouldQueue
{
    use Queueable;
    use InteractsWithQueue;
    use Dispatchable;
    use SerializesModels;

    public function handle(): void
    {
        $merchants = Merchant::query()
            ->with(['paymentMethods', 'transactions'])
            ->get();

        foreach ($merchants as $merchant) {
            GenerateInvoiceForMerchant::dispatch($merchant);
        }
    }
}
