<?php

namespace common\logic\User\CreditHistory\Repository;

use common\logic\AbstractRepository;
use common\logic\Order\Order\Model\Order;
use common\logic\User\CreditHistory\Model\CreditHistory;

class CreditHistoryRepository extends AbstractRepository
{
    protected CreditHistoryRepositoryQuery $query;

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

    public function getDefaultOptionsSearch(): array
    {
        return [
            'with' => [],
            'join_with' => [],
            'orderby' => CreditHistory::tableName() . '.date ASc',
            'attribute_id_producer' => CreditHistory::tableName() . '.id_producer'
        ];
    }

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