<?php

declare(strict_types=1);

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;

class BackupFailed extends Notification
{
    use Queueable;

    public function __construct(private array $errors)
    {
    }

    public function via(object $notifiable): array
    {
        return ['mail', 'slack'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->error()
            ->subject('[W·Dot] Backup failed')
            ->line('One or more backup tasks failed:')
            ->line(implode("\n", $this->errors));
    }

    public function toSlack(object $notifiable): SlackMessage
    {
        return (new SlackMessage)
            ->error()
            ->content('*W·Dot backup failed*')
            ->attachment(function ($a): void {
                $a->title('Errors')->content(implode("\n", $this->errors));
            });
    }
}
