<?php

namespace Tests\Services\OrderPackageSerivce\GetInnerParamsTest;

use App\OracleDOCOrderHeader;
use App\Order;
use App\Services\OracleDOCOrderHeaderService;
use App\Services\OrderPackageService;
use App\Services\OrderService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetInnerParamsTest extends TestCase
{
    /**
     * @var OrderPackageService $service
     * @var OracleDOCOrderHeaderService $orderHeaderService
     * @var OrderService $orderService
     */
    public $service;
    public $orderService;
    public $orderHeaderService;

    public function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderPackageService');
        $this->orderService = app('OrderService');
        $this->orderHeaderService = app('OracleDOCOrderHeaderService');
    }
    public function testGetInnerParamsTest()
    {
        $orderHeader = OracleDOCOrderHeader::query()->with('actAllocationDetails')->orderByDesc('AddTime')->first();
        $order = Order::query()->where('code',$orderHeader->orderno)->first();
        $inner_params = $this->service->getInnerParams($orderHeader,$order,[]);
        $this->assertNotEmpty($inner_params);
        $actAllocationDetails = $orderHeader->actAllocationDetails;

        foreach ($inner_params as $inner_param) {
            $detail = $actAllocationDetails->where('picktotraceid',$inner_param['logistic_number'])->first();
            $this->assertNotEmpty($detail);
            $this->assertEquals($inner_param['order_id'],$order->id);
            $this->assertEquals($inner_param['logistic_number'],$detail->picktotraceid);
            $this->assertNotEmpty($inner_param['created_at']);
            $this->assertNotEmpty($inner_param['updated_at']);
        }
    }
}
