<?php

namespace App\Notifications;

use App\Models\Application;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class NewApplicationNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(public Application $application)
    {
    }

    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject('Yeni Abonelik Başvurusu: '.$this->application->name)
            ->greeting('Yeni bir başvuru geldi!')
            ->line("Ad Soyad: {$this->application->name}")
            ->line("Telefon: {$this->application->phone}")
            ->line("İl/İlçe: {$this->application->il} / {$this->application->ilce}")
            ->line('Paket: '.$this->application->package?->name)
            ->action('Başvuruyu Görüntüle', url('/panel/applications/'.$this->application->id));
    }

    public function toArray(object $notifiable): array
    {
        return [
            'category' => 'basvuru',
            'application_id' => $this->application->id,
            'title' => 'Yeni Başvuru',
            'message' => "{$this->application->name} online başvuru formunu doldurdu.",
        ];
    }
}
