<?php

namespace App\Http\Controllers\Parking;
use App\Parking_db\Lps;
use App\Path;
use App\Car;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use App\Http\Controllers\Controller;


class CameraController extends Controller
{
    public function index(){
        return view('camera',['title'=>'camera','body'=>'camera']);
    }

    public function callapi(){
        $query = Path::all();
        $main=Car::all();
        $client=new \GuzzleHttp\Client();
        $res = $client->request('GET', 'http://192.168.5.17:8086/query?q=select+last(plate)%2C*+from+%22in%22&db=NCUT_MM&pretty=true',['verify' => false]);
        $response = json_decode($res->getBody()->getContents(), true);
        $dbname=$response['results'][0]['series'][0]['name'];
        $columns=$response['results'][0]['series'][0]['columns'][3];
        $values=$response['results'][0]['series'][0]['values'][0][3];
        $car = Lps::All()->Where('status','已進場');

        $client = new \GuzzleHttp\Client();
        $easy_darw="192.168.5.208:10008";
        $res = $client->GET($easy_darw."/api/v1/players");
        $response = json_decode($res->getBody()->__toString(), true);
        $total_stream=$response['rows'];
        
        $res = $client->GET("192.168.5.222:2375"."/containers/json?all=1");
        $response = json_decode($res->getBody()->__toString(), true);
        $docker_tag=$response;

//        return $values[0];
        return View('smart_parking.camera',['result'=>$query,'iresult'=>$main,'docker_tag'=>$docker_tag,'total_stream'=>$total_stream,'body'=>'camera','columns'=>$columns,"values"=>$values,'Cars'=>100-count($car)]);
    }

    
}
