<?php


namespace Tests\Services\RejectedBillService;


use App\OracleDOCASNHeader;
use App\Services\OwnerService;
use App\Services\RejectedBillService;
use App\Services\StoreItemService;
use App\Services\StoreService;
use App\Services\WarehouseService;
use App\Store;
use Carbon\Carbon;
use Tests\TestCase;

class GetLogisticNumberTest extends TestCase
{
    /**
     * @var StoreService $service
     * @var OwnerService $ownerService
     * @var WarehouseService $warehouseService
     *
     */
    public $service;
    public $asnHeaders;
    public $asnHeadersEdit;
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $dataInterval = intval(data_get(config('sync'), 'asn_sync.interval')) * 60 + 5;
        $startDate = \Illuminate\Support\Carbon::now()->subSeconds($dataInterval);
        $this->service=app(RejectedBillService::class);
        $this->asnHeaders=OracleDOCASNHeader::query()
            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
                $query->with(['lineStatus', 'qualityStatus','basSku']);
            }])
            ->where('addTime', '>=', $startDate)
            ->get();
        $this->asnHeadersEdit=OracleDOCASNHeader::query()
            ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
                $query->with(['lineStatus', 'qualityStatus','basSku']);
            }])
            ->where('EditTime', '>=', $startDate)
            ->whereColumn('EditTime', '<>', 'addTime')
            ->get();
    }
    public function testGetLogisticNumber(){
        if (empty($this->asnHeaders))return null;
        $addUpdateCollect=$this->service->getUpdateCollect($this->asnHeaders);
        if ($addUpdateCollect){
            $addLogisticNumber=$this->service->getLogisticNumberReturn($addUpdateCollect);
            $this->assertNotNull($addLogisticNumber);
        }
        if (empty($this->asnHeadersEdit))return null;
        $editUpdateCollect=$this->service->getUpdateCollect($this->asnHeadersEdit);
        if ($editUpdateCollect){
            $editLogisticNumber=$this->service->getLogisticNumberReturn($editUpdateCollect);
            $this->assertNotNull($editLogisticNumber);
        }
    }
}
