<?php
namespace Ceetrox\Managers\ChartManager;

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

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

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

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

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

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

    public function setType(string $value)
    {
        $this->type = $value;
    }

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

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

    public function getParentData(): 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->markLine)) $data['markLine']             = $this->markLine;

        return $data;
    }

}
