<?php

namespace App\Events;

use App\Models\ChecklistEntry;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class EntryDeleted implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(public readonly ChecklistEntry $entry) {}

    public function broadcastOn(): array
    {
        return [
            new Channel('unit.' . $this->entry->unit_id),
        ];
    }

    public function broadcastAs(): string
    {
        return 'EntryDeleted';
    }

    public function broadcastWith(): array
    {
        return [
            'entry_id' => $this->entry->id,
            'unit_id'  => $this->entry->unit_id,
        ];
    }
}
