<?php

namespace common\logic\Order\ProductOrder\Repository;

use common\logic\AbstractRepository;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder;

class ProductOrderRepository extends AbstractRepository
{
    protected ProductOrderRepositoryQuery $query;

    public function loadDependencies(): void
    {
        $this->query = $this->loadService(ProductOrderRepositoryQuery::class);
    }

    public function getDefaultOptionsSearch(): array
    {
        return [
            'with' => ['taxRate'],
            'join_with' => [],
            'orderby' => '',
            'attribute_id_producer' => ''
        ];
    }

    public function findOneProductOrderById(int $id)
    {
        return $productOrder = ProductOrder::searchOne([
            'id' => $id
        ]);
    }

    public function findProductOrdersByOrder(Order $order): array
    {
        return ProductOrder::find()->where(['id_order' => $order->id])->all();
    }
}