<?php

namespace common\logic\Product\Product\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Product\Product\Service\ProductDefinition;
use common\logic\Product\ProductCategory\Model\ProductCategory;
use common\logic\StatusInterface;

class ProductRepositoryQuery extends AbstractRepositoryQuery
{
    protected ProductDefinition $definition;

    public function loadDependencies(): void
    {
        $this->loadDefinition(ProductDefinition::class);
    }

    public function filterByName(string $name): self
    {
        $this->andWhere(['name' => $name]);
        return $this;
    }

    public function filterByDistribution(Distribution $distribution): self
    {
        $this->andWhere(['product_distribution.id_distribution' => $distribution->id]);
        return $this;
    }

    public function filterByProductCategory(ProductCategory $productCategory = null) : self
    {
        if($productCategory) {
            $this->andWhere(['product.id_product_category' => $productCategory->id]);
        }
        return $this;
    }
}