<?php
namespace Ceetrox\Sidekick\Views\Limitless\Linechart\DataManager;

class SeriesData
{
    private $name;
    private $categoryValues;
    private $index;

    public function __construct()
    {
        $this->categoryValues = [];
        $this->index = 0;
    }

    private function getName() : string
    {
        return $this->name;
    }

    private function getCategoryValues() : array
    {
        return $this->categoryValues;
    }

    private function getIndex() : int
    {
        return $this->index;
    }

    public function setName(string $name) : SeriesData
    {
        $this->name = $name;
        return $this;
    }

    public function setCategoryValues($values) : SeriesData
    {
        if(is_array($values)) {
            $this->categoryValues = array_merge($this->categoryValues, $values);
        } else {
            $this->categoryValues[] = $values;
        }

        return $this;
    }

    public function setIndex(int $index) : SeriesData
    {
        $this->index = $index;
        return $this;
    }

    public function toArray(): array
    {
        return [
            'name'  => $this->getName(),
            'data'  => $this->getCategoryValues(),
            'index' => $this->getIndex(),
        ];
    }

}
