<?php

namespace App\Notifications;

use App\Models\Announcement;
use Illuminate\Notifications\Messages\MailMessage;

class AnnouncementPublishedNotification extends BaseSchoolNotification
{
    public function __construct(public Announcement $announcement) {}

    public function toMail(object $notifiable): MailMessage
    {
        return $this->mailMessage(
            subject: 'Announcement: '.$this->announcement->title,
            greeting: 'Hello '.$notifiable->name.',',
            line: str($this->announcement->body)->limit(200)->toString(),
            actionUrl: url('/dashboard'),
            actionText: 'View Announcements',
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return $this->databasePayload(
            title: $this->announcement->title,
            body: str($this->announcement->body)->limit(160)->toString(),
            type: 'announcement',
            url: '/dashboard',
        );
    }
}
