<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class MissionTrackingUpdated implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(
        public readonly int $missionId,
        public readonly int $statusEventId,
        public readonly string $status,
        public readonly ?float $latitude,
        public readonly ?float $longitude,
        public readonly ?string $note,
        public readonly string $occurredAt,
    ) {}

    public function broadcastOn(): array
    {
        return [new Channel('mission.' . $this->missionId)];
    }

    public function broadcastAs(): string
    {
        return 'mission.tracking.updated';
    }

    public function broadcastWith(): array
    {
        return [
            'mission_id' => $this->missionId,
            'status_event_id' => $this->statusEventId,
            'status' => $this->status,
            'latitude' => $this->latitude,
            'longitude' => $this->longitude,
            'note' => $this->note,
            'occurred_at' => $this->occurredAt,
        ];
    }
}
