<?php

namespace App\Http\Controllers;

use App\Station;
use App\StationTypeBinMonitor;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class StationController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return void
     */
    public function index()
    {

    }
    public function monitorIndex()
    {
        $stations = Station::query()->with('stationType:name','parent:name')->whereHas('stationType',function($query){
            /** @var Builder $query */
            $query->where('name','料箱监视器');
        })->paginate(100);
        return view('station.monitor.index',compact('stations'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    public function show(Station $station)
    {
        //
    }
    public function monitorShow(Station $station)
    {
        $stationTypeBinMonitor = StationTypeBinMonitor::query()->where("station_id",$station->id)->first();
        $station->loadMissing([
            "currentStationTask.stationTaskCommodities.commodity.barcodes",
            "currentStationTask.stationTaskCommodities.materialBox",
            "currentStationTask.stationTaskBatches.batch",
            "currentStationTask.stationTaskMaterialBoxes.materialBox",
            "stationTypeBinMonitor",
        ]);
        if (!$station['stationTypeBinMonitor']){
            StationTypeBinMonitor::query()->create([
                'station_id' => $station['id'],
                'bin_row_length' => 4,
                'bin_column_length' => 5,
                'bin_wall_amount' => 2,
            ]);
            $station->load("stationTypeBinMonitor");
        }
        return view('station.monitor.show',compact('station'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Station  $station
     * @return \Illuminate\Http\Response
     */
    public function edit(Station $station)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Station  $station
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Station $station)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Station  $station
     * @return \Illuminate\Http\Response
     */
    public function destroy(Station $station)
    {
        //
    }

}
