<?php

namespace App\Http\Controllers;

use App\Domain\Financial\Models\Invoice;
use Illuminate\Support\Facades\Gate;

class InvoicePrintController extends Controller
{
    public function __invoke(Invoice $invoice)
    {
        Gate::authorize('invoices.view');

        $invoice->load(['items', 'payments', 'billable']);

        $invoice->increment('print_count');
        $invoice->update(['last_printed_at' => now()]);

        return view('print.invoice', compact('invoice'));
    }
}
