<?php

namespace App\Modules\FINANCE\Services;

use App\Modules\FINANCE\Models\Invoice;
use App\Modules\FINANCE\Notifications\InvoiceReminderNotification;
use Illuminate\Support\Facades\Notification;

class NotificationService
{
    /**
     * Send invoice to client.
     */
    public function sendInvoice(Invoice $invoice)
    {
        $client = $invoice->client;
        if (!$client || !$client->email) {
            return false;
        }

        Notification::route('mail', $client->email)
            ->notify(new InvoiceReminderNotification($invoice, 'upcoming'));

        return true;
    }

    /**
     * Send payment reminder.
     */
    public function sendReminder(Invoice $invoice, $type = 'overdue')
    {
        $client = $invoice->client;
        if (!$client || !$client->email) {
            return false;
        }

        Notification::route('mail', $client->email)
            ->notify(new InvoiceReminderNotification($invoice, $type));

        return true;
    }
}
