<?php

namespace App\Notifications;

use App\Services\Email\EmailConfigurationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

abstract class BaseSchoolNotification extends Notification implements ShouldQueue
{
    use Queueable;

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

        if (app(EmailConfigurationService::class)->canSendAutomated()) {
            $channels[] = 'mail';
        }

        return $channels;
    }

    protected function mailMessage(string $subject, string $greeting, string $line, ?string $actionUrl = null, ?string $actionText = null): MailMessage
    {
        $mail = (new MailMessage)
            ->subject($subject)
            ->greeting($greeting)
            ->line($line);

        if ($actionUrl && $actionText) {
            $mail->action($actionText, $actionUrl);
        }

        return $mail->line('Thank you for using '.config('southend.app_name').'.');
    }

    /**
     * @return array<string, mixed>
     */
    protected function databasePayload(string $title, string $body, string $type, ?string $url = null): array
    {
        return [
            'title' => $title,
            'body' => $body,
            'type' => $type,
            'url' => $url,
        ];
    }
}
