<?php

namespace App\Notifications;

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

class InitialDocumentsSignedNotification extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * @param  array<int, array{document_id?: int, name?: string}>  $documents
     */
    public function __construct(
        public readonly Client $client,
        public readonly array $documents = [],
    ) {}

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

    public function toArray($notifiable): array
    {
        $count = count($this->documents);

        return [
            'type'        => 'initial_documents_signed',
            'title'       => 'Initial documents e-signed',
            'message'     => $this->client->full_name . ' e-signed ' . $count . ' ' . Str::plural('document', $count),
            'client_id'   => $this->client->id,
            'client_name' => $this->client->full_name,
            'documents'   => collect($this->documents)->pluck('name')->filter()->values()->all(),
        ];
    }

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