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

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

Class PieChartData extends ChartDataManager {

    private ?string  $subtitle;
    private ?string  $pieType;
    private ?bool    $hasLabel;
    private ?bool    $hasLabelOnEmphasis;

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

        $this->subtitle = null;
        $this->pieType = null;
        $this->hasLabel = null;
        $this->hasLabelOnEmphasis = null;
    }

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

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

    public function setSubtitle(string $value)
    {
        $this->subtitle = $value;
    }

    public function setPieType(string $value)
    {
        $this->pieType = $value;
    }

    public function setHasLabel(bool $value)
    {
        $this->hasLabel = $value;
    }

    public function setHasLabelOnEmphasis(bool $value)
    {
        $this->hasLabelOnEmphasis = $value;
    }

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

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

        if(!is_null($this->subtitle))                   $data['subtitle'] = $this->subtitle;
        if(!is_null($this->pieType))                    $data['pieType'] = $this->pieType;
        if(!is_null($this->hasLabel))                   $data['label'] = $this->hasLabel;
        if(!is_null($this->hasLabelOnEmphasis))         $data['labelOnEmphasis'] = $this->hasLabelOnEmphasis;

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

        return $data;
    }

}