<?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;
use App\Models\RideRequest;

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

    public $rideRequest;

    public function __construct(RideRequest $rideRequest)
    {
        $this->rideRequest = $rideRequest;
    }

    public function broadcastOn()
{
    return new Channel('ride-requests'); // Not PrivateChannel
}

    // 🔹 This ensures we broadcast a simple event name
    public function broadcastAs(): string
    {
        return 'RideRequested';
    }

    // 🔹 This ensures only needed data is sent
    public function broadcastWith(): array
    {
        return [
            'pickup_address'  => $this->rideRequest->pickup_address,
            'dropoff_address' => $this->rideRequest->dropoff_address,
            'vehicle_type'    => $this->rideRequest->vehicle_type,
        ];
    }
}
