<?php


namespace Tests\Services\StoreItemService;


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

class GetParamsByAsnDetailsTest extends TestCase
{
    /**
     * @var StoreService $service
     * @var OwnerService $ownerService
     * @var WarehouseService $warehouseService
     *
     */
    public $service;
    public $asnHeaders;
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $this->service=app(StoreItemService::class);
        $startDate = \Illuminate\Support\Carbon::now()->setSeconds(30);
        $this->asnHeaders=OracleDOCASNHeader::query()
            ->with(['asnType', 'asnStatus'])
            ->where('addTime', '>=', $startDate)
            ->get();
    }
    public function testGetParamsByAsnHeader()
    {
        if (empty($this->asnHeaders)) return null;
        $asnDetails=$this->service->getAsnDetailsByAsnHerder($this->asnHeaders);
        $stores = Store::query()->whereIn('asn_code',array_unique(data_get($asnDetails,'*.asnno')))->get();
        $store_asn_code_map = [];
        foreach ($stores as $store) {
            $store_asn_code_map[$store->asn_code]= $store;
        }
        $params=$this->service->getParamsByAsnDetails($asnDetails,$store_asn_code_map);
        if(count($params)> 0){
           $this->assertNotEmpty($params);
        }else{
            $this->assertEmpty($params);
        }
    }
}
