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

use Ceetrox\Managers\ChartManager\ChartDataManager;
use Ceetrox\Managers\ChartManager\ISeriesData;

Class LineChartData extends ChartDataManager {

    private array    $titles;
    private ?bool    $hasBoundaryGap;
    private ?bool    $isInverted;
    private ?bool    $hasDataZoom;

    private ?bool    $showPointValues;
    private ?bool    $isArea;

    public function __construct()
    {
        parent::__construct();

        $this->titles = [];
        $this->hasBoundaryGap = null;
        $this->isInverted = null;
        $this->hasDataZoom = null;

        $this->showPointValues = null;
        $this->isArea = null;
    }

    public static function getInstance(): LineChartData
    {
        return new self;
    }

    public static function getSeriesDataInstance(): ISeriesData
    {
        return new LineSeriesData();
    }

    public function setTitle($value)
    {
        if(is_array($value)) {
            $this->titles = array_merge($this->titles, $value);
        } else {
            $this->titles[] = $value;
        }
    }

    public function setHasBoundaryGap(bool $value)
    {
        $this->hasBoundaryGap = $value;
    }

    public function setIsInverted(bool $value)
    {
        $this->isInverted = $value;
    }

    public function setHasDataZoom(bool $value)
    {
        $this->hasDataZoom = $value;
    }

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

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

    public function toJson(): string
    {
        return json_encode($this->toArray());
    }

    public function toArray(): array
    {
        // set if conditions so we can only pass attributes that are set.
        // if attributes are not set then we can check and use the manual parameters of the charts.

        $data = [];

        if(count($this->titles) > 0)                    $data['titles'] = $this->titles;
        if(!is_null($this->hasBoundaryGap))             $data['boundaryGap'] = $this->hasBoundaryGap;
        if(!is_null($this->isInverted))                 $data['inverted'] = $this->isInverted;
        if(!is_null($this->hasDataZoom))                $data['dataZoom'] = $this->hasDataZoom;
        if(!is_null($this->showPointValues))            $data['pointValues'] = $this->showPointValues;
        if(!is_null($this->isArea))                     $data['isArea'] = $this->isArea;

        $data = array_merge($data, $this->getParentData());

        return $data;
    }

}