<?php

namespace App\Notifications;

use App\Models\Invoice;
use Illuminate\Notifications\Messages\MailMessage;

class FeeDueReminderNotification extends BaseSchoolNotification
{
    public function __construct(
        public Invoice $invoice,
        public bool $overdue = false,
    ) {}

    public function toMail(object $notifiable): MailMessage
    {
        $student = $this->invoice->student?->full_name ?? 'Student';
        $label = $this->overdue ? 'Overdue fee reminder' : 'Fee due reminder';

        return $this->mailMessage(
            subject: "{$label}: {$this->invoice->invoice_number}",
            greeting: 'Hello '.$notifiable->name.',',
            line: "{$student} has an outstanding balance of MWK ".number_format((float) $this->invoice->balance_due, 2)." due on {$this->invoice->due_date?->format('d M Y')}.",
            actionUrl: url('/parent/fees'),
            actionText: 'View Fees',
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return $this->databasePayload(
            title: $this->overdue ? 'Overdue fees' : 'Fee reminder',
            body: "Invoice {$this->invoice->invoice_number} — MWK ".number_format((float) $this->invoice->balance_due, 2).' outstanding',
            type: 'fee',
            url: '/parent/fees',
        );
    }
}
