<commit_before><?php
/**
 * @author <EMAIL>
 * (c) ABOUT YOU GmbH
 */

namespace AboutYou\SDK\Model;

use \AY;
use AboutYou\SDK\Factory\ModelFactoryInterface;
use AboutYou\SDK\Model\ProductSearchResult\FacetCounts;
use AboutYou\SDK\Model\ProductSearchResult\PriceRange;
use AboutYou\SDK\Model\ProductSearchResult\SaleCounts;

class ProductSearchResult
{
    /** @var Product[] */
    protected $products;

    /** @var string */
    protected $pageHash;

    /** @var integer */
    protected $productCount;

    /** @var SaleCounts */
    protected $saleCounts;

    /** @var PriceRange[] */
    protected $priceRanges;

    /** @var FacetCounts[] */
    protected $facets;

    /** @var FacetCounts[] */
    protected $productFacets;

    /** @var Category[] */
    protected $categories = array();

    /**
     * @var array
     * @deprcated
     */
    protected $rawFacets;

    protected function __construct()
    {
        $this->products = array();
    }

    /**
     * @param \stdClass $jsonObject
     * @param ModelFactoryInterface $factory
     *
     * @return static
     */
    public static function createFromJson(\stdClass $jsonObject, ModelFactoryInterface $factory)
    {
        $productSearchResult = new static();

        $productSearchResult->pageHash = $jsonObject->pageHash;
        $productSearchResult->productCount = $jsonObject->product_count;
        $productSearchResult->rawFacets = $jsonObject->facets;

        foreach ($jsonObject->products as $key => $jsonProduct) {
            $productSearchResult->products[$key] = $factory->createProduct($jsonProduct);
        }

        $productSearchResult->parseFacets($jsonObject->facets, $factory);

        return $productSearchResult;
    }

    /**
     * @return string
     */
    public function getPageHash()
    {
        return $this->pageHash;
    }

    /**
     * @return Product[]
     */
    public function getProducts()
    {
        return $this->products;
    }

    protected function parseFacets($jsonObject, ModelFactoryInterface $factory)
    {
        if (isset($jsonObject->categories)) {
            $this->categories = $factory->createCategoriesFacets($jsonObject->categories);
            unset($jsonObject->categories);
        }
        if (isset($jsonObject->prices)) {
            $this->priceRanges = $factory->createPriceRanges($jsonObject->prices);
            unset($jsonObject->prices);
        }
        if (isset($jsonObject->sale)) {
            $this->saleCounts = $factory->createSaleFacet($jsonObject->sale);
            unset($jsonObject->sale);
        }
        if (isset($jsonObject->product_facets)) {
            $this->productFacets = $factory->createProductFacets($jsonObject->product_facets);
            unset($jsonObject->product_facets);
        }<commit_msg>added setProducts() to search result<commit_after><?php
/**
 * @author <EMAIL>
 * (c) ABOUT YOU GmbH
 */

namespace AboutYou\SDK\Model;

use \AY;
use AboutYou\SDK\Factory\ModelFactoryInterface;
use AboutYou\SDK\Model\ProductSearchResult\FacetCounts;
use AboutYou\SDK\Model\ProductSearchResult\PriceRange;
use AboutYou\SDK\Model\ProductSearchResult\SaleCounts;

class ProductSearchResult
{
    /** @var Product[] */
    protected $products;

    /** @var string */
    protected $pageHash;

    /** @var integer */
    protected $productCount;

    /** @var SaleCounts */
    protected $saleCounts;

    /** @var PriceRange[] */
    protected $priceRanges;

    /** @var FacetCounts[] */
    protected $facets;

    /** @var FacetCounts[] */
    protected $productFacets;

    /** @var Category[] */
    protected $categories = array();

    /**
     * @var array
     * @deprcated
     */
    protected $rawFacets;

    protected function __construct()
    {
        $this->products = array();
    }

    /**
     * @param \stdClass $jsonObject
     * @param ModelFactoryInterface $factory
     *
     * @return static
     */
    public static function createFromJson(\stdClass $jsonObject, ModelFactoryInterface $factory)
    {
        $productSearchResult = new static();

        $productSearchResult->pageHash = $jsonObject->pageHash;
        $productSearchResult->productCount = $jsonObject->product_count;
        $productSearchResult->rawFacets = $jsonObject->facets;

        foreach ($jsonObject->products as $key => $jsonProduct) {
            $productSearchResult->products[$key] = $factory->createProduct($jsonProduct);
        }

        $productSearchResult->parseFacets($jsonObject->facets, $factory);

        return $productSearchResult;
    }

    /**
     * @return string
     */
    public function getPageHash()
    {
        return $this->pageHash;
    }

    /**
     * @param Product[] $products
     */
    public function setProducts($products)
    {
        $this->products = $products;
    }

    /**
     * @return Product[]
     */
    public function getProducts()
    {
        return $this->products;
    }

    protected function parseFacets($jsonObject, ModelFactoryInterface $factory)
    {
        if (isset($jsonObject->categories)) {
            $this->categories = $factory->createCategoriesFacets($jsonObject->categories);
            unset($jsonObject->categories);
        }
        if (isset($jsonObject->prices)) {
            $this->priceRanges = $factory->createPriceRanges($jsonObject->prices);
            unset($jsonObject->prices);
        }
        if (isset($jsonObject->sale)) {
            $this->saleCounts = $factory->createSaleFacet($jsonObject->sale);
            unset($jsonObject->sale);
        }
        if (isset($jsonObject->product_facets)) {
            $this->productFacets = $factory->createProductFacets($jsonObject->product_facets);
            unset($jsonObject->product_facets);
        }
{'fraction_non_alphanumeric': 0.1362847222222222, 'fraction_numerical': 0.0, 'mean_word_length': 2.6164469554300065, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '362560', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1605, 'n_words': 288}