<?php

namespace App\Representation;

use Doctrine\ORM\Tools\Pagination\Paginator;
use JMS\Serializer\Annotation as Serializer;

class PaginatedProducts
{
    /**
     * @Serializer\Type("array<App\Entity\Product>")
     * @Serializer\Groups({"list"})
     */
    private $data;

    /**
     * @Serializer\Groups({"list"})
     */
    private $meta;

    /**
     * Products constructor.
     * @param $data
     */
    public function __construct(Paginator $paginator, $page)
    {
        $this->data = iterator_to_array($paginator);

        $this->meta = [
            'page' => $page,
            'items_on_current_page' => count($this->data),
            'total_number_of_items' => count($paginator)
        ];
    }

    /**
     * @return mixed
     */
    public function getData()
    {
        return $this->data;

    }

    /**
     * @return mixed
     */
    public function getMeta()
    {
        return $this->meta;
    }
}