<?php

declare(strict_types=1);

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Laravel\Cashier\Subscription;

class SubscriptionCancelledNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public Subscription $subscription,
    ) {}

    /** @return array<int, string> */
    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        $pricingUrl = 'https://'.config('app.domains.marketing').'/pricing';

        return (new MailMessage)
            ->subject('Subscription Cancelled')
            ->greeting("Hello {$notifiable->name},")
            ->line("Your subscription **{$this->subscription->type}** has been cancelled.")
            ->line('Your service will remain active until the end of your current billing period.')
            ->line('You can resubscribe at any time to continue using our services.')
            ->action('View Plans', $pricingUrl)
            ->line('We hope to see you again soon!');
    }

    /** @return array<string, mixed> */
    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'subscription_cancelled',
            'subscription_id' => $this->subscription->id,
            'subscription_type' => $this->subscription->type,
            'message' => "Subscription \"{$this->subscription->type}\" has been cancelled.",
        ];
    }
}
