<?php

namespace App\Http\Controllers;

use App\Menu;
use App\Mqtt_data_request;
use App\Stanice;
use App\User;
use App\WuDefinicePristupu;
use Auth;
use Illuminate\Support\Carbon;

class PrehledController extends Controller
{

    private $dataPrehledu = [];

    public function index()
    {
        $this->getPocetUseru();
        $this->getPocetStanic();
        $this->getPocetZivychStanic();
        $this->getPocetDat();
        $this->pocetSynchroNaWu();
        return view('prehled',['user'=> Auth::user(),'menu' => Menu::getData(), 'statistiky' => $this->dataPrehledu]);
    }

    private function getPocetUseru(): void
    {
        $this->dataPrehledu['uzivatelu'] = User::count();
    }

    private function getPocetStanic(): void
    {
        $this->dataPrehledu['stanice'] = Stanice::count();
    }

    private function getPocetZivychStanic(): void
    {
        $this->dataPrehledu['ziveStanice'] = Stanice::where('registrovano','=',1)->count();
    }

    private function getPocetDat(): void
    {
        $this->dataPrehledu['prijateZpravy24'] = Mqtt_data_request::whereBetween('vlozeny',[Carbon::yesterday(), Carbon::now()])->count();
    }

    private function pocetSynchroNaWu(): void
    {
        $this->dataPrehledu['synchro'] = WuDefinicePristupu::count();
    }


}
