<?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 SubscriptionCreatedNotification 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
    {
        $dashboardUrl = 'https://'.config('app.domains.account').'/dashboard';

        return (new MailMessage)
            ->subject('Subscription Confirmed')
            ->greeting("Welcome aboard, {$notifiable->name}!")
            ->line("Your subscription **{$this->subscription->type}** has been created successfully.")
            ->line('Your service is being provisioned and will be ready shortly.')
            ->action('Go to Dashboard', $dashboardUrl)
            ->line('Thank you for choosing EZSCALE!');
    }

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