<?php

declare(strict_types=1);

namespace Builder\Core\Notifications;

use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

final class UserInvitedNotification extends Notification
{
    public function __construct(
        private readonly string $token,
        private readonly bool $isReset = false,
    ) {}

    /** @return list<string> */
    public function via(): array
    {
        return ['mail'];
    }

    public function toMail(mixed $notifiable): MailMessage
    {
        $url = route('builder.invite.show', $this->token)
            .'?email='.urlencode((string) $notifiable->email);

        if ($this->isReset) {
            return (new MailMessage)
                ->subject(__('builder::builder.invite.reset_email_subject'))
                ->greeting(__('builder::builder.invite.email_greeting', ['name' => $notifiable->name]))
                ->line(__('builder::builder.invite.reset_email_intro'))
                ->action(__('builder::builder.invite.reset_email_action'), $url)
                ->line(__('builder::builder.invite.email_expiry', ['hours' => 24]));
        }

        return (new MailMessage)
            ->subject(__('builder::builder.invite.email_subject'))
            ->greeting(__('builder::builder.invite.email_greeting', ['name' => $notifiable->name]))
            ->line(__('builder::builder.invite.email_intro'))
            ->action(__('builder::builder.invite.email_action'), $url)
            ->line(__('builder::builder.invite.email_expiry', ['hours' => 24]));
    }
}
