<?php


namespace Tests\Services\StationCacheShelfGridService;
use App\Services\StationCacheShelfGridService;
use App\Station;
use App\StationCacheShelfGrid;
use Tests\TestCase;

class LightOffTest extends TestCase
{
    /** @var StationCacheShelfGridService $stationCacheShelfGridService */
    protected $stationCacheShelfGridService;
    protected $data = [];

    protected function setup(): void
    {
        parent::setUp();
        $this->stationCacheShelfGridService = app(StationCacheShelfGridService::class);
        $row = 2;
        $col = 1;
        $gridIndex = ($row-1)*3 + (3-$col);
        $this->data['station'] = factory(Station::class)->create();
        $this->data['stationCacheShelfGrid'] = factory(StationCacheShelfGrid::class)->create(['station_id' => $this->data['station']['id'],'grid_id'=>$gridIndex]);
        $this->data['locCode'] = 'HAI'.$this->data['station']['code'].'-0'.$col.'-0'.$row;
        $this->data['PTLAction'] = 0;
    }

    public function testLightOff()
    {
        $this->stationCacheShelfGridService->lightOff($this->data['locCode'],$this->data['PTLAction']);
        $grid = StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->first();
        $this->assertEquals($grid['id'],$this->data['stationCacheShelfGrid']['id']);
        $this->assertEquals($grid['station']['id'],$this->data['stationCacheShelfGrid']['station_id']);
        $this->assertEquals($grid['material_box_id'],null);
        $this->assertEquals($grid['status'],0);

    }

    protected function tearDown(): void
    {
        Station::query()->where('id',$this->data['station']['id'])->delete();
        StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->delete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }

}
