<?php

namespace App\Notifications;

use App\Models\Client\Client;
use App\Models\Contact\Hub\ContactMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;

class InboundClientEmailNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public readonly ContactMessage $message,
        public readonly Client $client,
    ) {}

    public function via($notifiable): array
    {
        return ['database', 'broadcast'];
    }

    public function toArray($notifiable): array
    {
        $preview = $this->message->subject
            ?: Str::limit(strip_tags($this->message->body_text ?? ''), 80);

        return [
            'type'        => 'inbound_client_email',
            'title'       => 'New Email from Client',
            'message'     => $preview,
            'client_id'   => $this->client->id,
            'client_name' => $this->client->full_name,
            'message_id'  => $this->message->id,
        ];
    }

    public function toBroadcast($notifiable): array
    {
        return $this->toArray($notifiable);
    }
}
