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

use Ceetrox\Managers\ChartManager\ISeriesData;

class PieSeriesData implements ISeriesData
{
    private ?string $name;
    private array   $data;
    private int     $index;

    public function __construct()
    {
        $this->name = null;
        $this->data = [];
        $this->index = 0;
    }

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

    public function addData(string $name, float $value)
    {
        $data = (object)[];
        $data->name = $name;
        $data->value = $value;

        $this->data[] = $data;
    }

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

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

        $data['data'] = $this->data;
        $data['name']  = $this->name;

        return $data;
    }

}
