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

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

Class BarChartData extends ChartDataManager {

    private ?bool    $isHorizontal;
    private ?bool    $showBarValues;

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

        $this->isHorizontal = null;
        $this->showBarValues = null;
    }

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

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

    public function setIsHorizontal(bool $value)
    {
        $this->isHorizontal = $value;
    }

    public function setShowBarValues(bool $value)
    {
        $this->showBarValues = $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(!is_null($this->isHorizontal))               $data['horizontal'] = $this->isHorizontal;
        if(!is_null($this->showBarValues))              $data['barValues'] = $this->showBarValues;

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

        return $data;
    }

}