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

class SeriesData
{
    private string    $name;
    private array     $categoryValues;
    private int       $index;
    private ?string   $type;
    private ?string   $stackName;
    private ?bool     $showPointValues;
    private ?bool     $isArea;
    private ?string   $markLine;

    public function __construct()
    {
        $this->categoryValues = [];
        $this->index = 0;
        $this->type = null;
        $this->stackName = null;
        $this->showPointValues = null;
        $this->isArea = null;
        $this->markLine = null;
    }

    public 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 setType(string $value) : SeriesData
    {
        $this->type = $value;
        return $this;
    }

    public function setStackName(string $value) : SeriesData
    {
        $this->stackName = $value;
        return $this;
    }

    public function setShowPointValues(bool $value) : SeriesData
    {
        $this->showPointValues = $value;
        return $this;
    }

    public function setIsArea(bool $value) : SeriesData
    {
        $this->isArea = $value;
        return $this;
    }

    public function setMarkLine(string $value) : SeriesData
    {
        $this->markLine = $value;
        return $this;
    }

    public function toArray(): array
    {
        $data = [];

        $data['name']  = $this->name;
        $data['data']  = $this->categoryValues;
        $data['index'] = $this->index;

        if(!is_null($this->type)) $data['type']                     = $this->type;
        if(!is_null($this->stackName)) $data['stacked']             = $this->stackName;
        if(!is_null($this->showPointValues)) $data['pointValues']   = $this->showPointValues;
        if(!is_null($this->markLine)) $data['markLine']             = $this->markLine;
        if(!is_null($this->isArea)) $data['isArea']                 = $this->isArea;

        return $data;
    }

}
