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

use Ceetrox\Managers\ChartManager\ChartDataManager;

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 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
    {
        // 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->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;
    }

}