<?php

namespace Tests\Services\ForeignHaiRoboticsService;
use App\MaterialBox;
use App\Services\ForeignHaiRoboticsService;
use App\Station;
use App\StationTaskMaterialBox;
use Tests\TestCase;
use App\Traits\TestMockSubServices;

class TaskUpdateTest extends TestCase
{
    use TestMockSubServices;
    /** @var ForeignHaiRoboticsService $service */
    public $service;
    private $data;
    private $amount=2;
    function setUp(): void
    {
        parent::setUp();
        $this->service = app('ForeignHaiRoboticsService');
        $this->data['station'] = factory(Station::class)->create();
        $this->data['materialBox'] = factory(MaterialBox::class)->create();
        $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
            'station_id' => 1,
            'material_box_id' => $this->data['materialBox']['id'],

        ]);
        $this->data['task']=[
            'taskCode'=>md5(microtime(true)),
            'updateEventType' => 0,
            'status'=>0,
            'binCode'=>$this->data['materialBox']['code']
        ];
    }

    public function testReturned()
    {
        $this->assertTrue(true);
    }

    public function testMissionFailed()
    {
        $this->data['task']['status']=1;
        $this->assertFalse($this->service->taskUpdate(
            $this->data['task']['taskCode'],
            $this->data['task']['updateEventType'],
            $this->data['task']['status'],
            $this->data['task']['binCode']
        ));
    }

    public function testMissionFailed2()
    {
        $this->data['task']['status']=1;
        $this->assertFalse($this->service->taskUpdate(
            $this->data['task']['taskCode'],
            $this->data['task']['updateEventType'],
            $this->data['task']['status'],
            $this->data['task']['binCode']
        ));
    }

    function tearDown(): void
    {
        Station::query()
            ->whereIn('id',[$this->data['task']['station']['id']??''])
            ->delete();
        MaterialBox::query()
            ->whereIn('id',[$this->data['task']['materialBox']['id']??''])
            ->delete();
        StationTaskMaterialBox::query()
            ->whereIn('id',[$this->data['task']['stationTaskMaterialBox']['id']??''])
            ->delete();
        parent::tearDown();
    }
}
