<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractRepository;
use domain\Product\Accessory\Accessory;
use domain\Product\Product\Product;

class ProductAccessoryRepository extends AbstractRepository
{
    protected ProductAccessoryRepositoryQuery $query;

    public function loadDependencies(): void
    {
        $this->loadQuery(ProductAccessoryRepositoryQuery::class);
    }

    public function getDefaultOptionsSearch(): array
    {
        return [
            self::WITH => [],
            self::JOIN_WITH => ['accessoryRelation'],
            self::ORDER_BY => 'accessory.name ASC',
            self::ATTRIBUTE_ID_PRODUCER => ''
        ];
    }

    public function findOneProductAccessory(Product $product, Accessory $accessory): ?ProductAccessory
    {
        return $this->createDefaultQuery()
            ->filterByProduct($product)
            ->filterByAccessory($accessory)
            ->findOne();
    }

    public function findProductAccessoriesByAccessory(Accessory $accessory): array
    {
        return $this->createDefaultQuery()
            ->filterByAccessory($accessory)
            ->find();
    }
}