<?php

namespace App\Notifications\Subscription;

use App\Models\Subscription;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SubscriptionRenewalOrderNotification extends Notification
{
    use Queueable;

    public Subscription $subscription;

    /**
     * Create a new notification instance.
     */
    public function __construct($subscription)
    {
        $this->subscription = $subscription;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject(trans('email.subscription_renewal_order.subject', [
                'order_reference' => $this->subscription->lastOrder()->order_reference,
                'reference_id' => $this->subscription->reference_id,
            ]))->markdown('emails.Subscription.renewal_order', [
                'reference_id' => $this->subscription->reference_id,
                'order' => $this->subscription->lastOrder(),
            ]);
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'order_reference' => $this->subscription->lastOrder()->order_reference,
            'title' => 'New Order #' . $this->subscription->lastOrder()->order_reference . ' created for renewal of Subscription #' . $this->subscription->reference_id,
        ];
    }
}
