<?php

namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Auth;

class RemoteApiService
{
    /**
     * Create a new class instance.
     */
    public function __construct()
    {
        //
    }

    
    public function fetchCurrentLocations($login)
    {
        $response = Http::withBasicAuth('geeth', 'abc123')
        ->withHeaders([
            'Accept' => 'application/json',
            'Content-Type' => 'application/json',
        ])
        ->send('POST', 'http://94.156.189.111:8080/XCore/API/gps/current', [
            'body' => json_encode([
                'empid' => ''.Auth::user()->employee,
                'rollid' => ''.Auth::user()->rolls
            ]),
        ]);
        if ($response->successful()) {
            $vehicles = $response->json(); // This will be an array of arrays
        } else {
            $vehicles = []; // Or handle error/log
        }


        return $response->successful() ? $response->json() : [];
    }
}
