<?php

namespace Tests\Services\OrderService\GetCreateOrderModelsTest;

use App\OracleDOCOrderHeader;
use App\Services\common\DataHandlerService;
use App\Services\LogisticService;
use App\Services\OracleDOCOrderHeaderService;
use App\Services\OrderService;
use App\Services\OwnerService;
use App\Services\ShopService;
use App\Services\WarehouseService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetCreateOrderModelsTest extends TestCase
{
    /**
     * @var OrderService $service
     * @var OracleDOCOrderHeaderService $orderHeaderService
     * @var DataHandlerService $dataHandlerService
     * @var OwnerService $ownerService
     * @var LogisticService $logisticService
     * @var ShopService $shopService
     * @var WarehouseService $warehouseService
     */
    public $service;
    public $orderHeaderService;
    public $dataHandlerService;
    public $ownerService;
    public $logisticService;
    public $shopService;
    public $warehouseService;
    public function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderService');
        $this->orderHeaderService = app('OracleDocOrderHeaderService');
        $this->dataHandlerService=app('DataHandlerService');
        $this->ownerService=app('OwnerService');
        $this->logisticService=app('LogisticService');
        $this->shopService=app('ShopService');
        $this->warehouseService=app('WarehouseService');
    }

    public function testGetCreateModels()
    {
        $orderHeader = OracleDOCOrderHeader::query()->orderByDesc('addTime')->first();

        $orderHeaders= collect($orderHeader);
        $warehouse_map = $this->getWareHouseMap($orderHeaders);
        $owner_map = $this->getOwnersMap($orderHeaders);
        $logistic_map = $this->getLogisticMap($orderHeaders);
        $shop_map = $this->getShopMap($orderHeaders);

        $create_order = $this->service->getCreateOrderModel($orderHeader,$warehouse_map,$owner_map,$logistic_map,$shop_map);
        $this->assertNotEmpty($create_order);

    }

    public function getWareHouseMap($orderHeaders)
    {
        $warehouses = $this->warehouseService->getByWmsOrders($orderHeaders);
        return $this->dataHandlerService->dataHeader(['code'],$warehouses);
    }
    public function getOwnersMap($orderHeaders)
    {
        $owners = $this->ownerService->getByWmsOrders($orderHeaders);
        return $this->dataHandlerService->dataHeader(['code'],$owners);
    }
    public function getLogisticMap($orderHeaders)
    {
        $logistics = $this->logisticService->getByWmsOrders($orderHeaders);
        return $this->dataHandlerService->dataHeader(['code'],$logistics);
    }
    public function getShopMap($orderHeaders)
    {
        $shops = $this->shopService->getByWmsOrders($orderHeaders);
        return $this->dataHandlerService->dataHeader(['code'],$shops);
    }

}
