<?php

namespace KupShop\OrderingBundle\Tests\Purchase;

use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
use KupShop\OrderingBundle\Util\Purchase\PurchaseUtil;

trait PurchaseTestTrait
{
    private function createPurchaseState(array $items = [], ?int $deliveryType = null): PurchaseState
    {
        $this->prepareCart();

        if (!empty($items)) {
            foreach ($items as $item) {
                $this->insertProduct($item['id_product'], $item['id_variation'] ?? null, $item['pieces']);
            }
        } else {
            $this->insertProduct(9);
            $this->insertProduct(2, 9, 2);
        }

        if ($deliveryType) {
            $this->setDeliveryType($deliveryType);
        }

        $this->cart->createFromDB();

        $purchaseUtil = $this->get(PurchaseUtil::class);

        return $purchaseUtil->createStateFromCart($this->cart);
    }
}
