<?php


namespace App\Http\Controllers\api\thirdPart\haiq;




use App\Services\CacheShelfService;
use App\Services\ForeignHaiRoboticsService;
use App\Station;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class LightController
{
    protected $request;

    /** @var ForeignHaiRoboticsService $service */
    private $service;
    public function __construct(){
        $this->service=app('ForeignHaiRoboticsService');
    }

    public function lightOn($post){
    }
    public function lightOff(Request $request){
    }

    /**
     * @param Request $request {"areaCode":"1004","locCode":"HAIB2-02-03","displayInfo":null,"PTLAction":0,"PTLSettings":null}
     * @return array
     */
    public function update(Request $request){// 拍灯以后的消息发至此处
        $station = Station::query()->with('stationType')->where('code',$request['locCode'])->first();
        if( ($station ?? false) && ($station->stationType->name ?? false) && $station->stationType->name == '缓存架' ){  // 拍灯 推送任务
            if($request['PTLAction'] !== 0) return ['location' => 200,'errMsg' => 'is cacheShelf','data' => $request->all()];
            /** @var CacheShelfService $cacheShelfService */
            $cacheShelfService = app(CacheShelfService::class);
            $result =   $cacheShelfService->lightOffTask($request['locCode'],$request['PTLAction']);
            return ['location'=>$result['success'] ? 200 :0,'errMsg'=>$result['errMsg'] ?? null,'data'=>$request->all()];
        }
        $success = $request->input('success');
        $location = $success?200:0;
        app('LogService')->log(__METHOD__,__FUNCTION__,'拍灯：'.json_encode($request->all()));
        return ['location'=>$location,'errMsg'=>'','data'=>$request->all()];
    }

}
