<?php

namespace WHOOP\Entities;

class Dataset
{
  /**
   * @var Attribute[]
   */
  protected array $data = [];

  public function __construct(?array $data = []) {
    if (!empty($data)) {
      foreach ($data as $dataKey => $dataValue) {
        $this->setDataValue($dataKey, $dataValue);
      }
    }
  }

  public function setDataValue(string $dataKey, mixed $dataValue): self
  {
    $this->data[$dataKey] = new Attribute('data-' . $dataKey, $dataValue);

    return $this;
  }

  public function unsetDataValue(string $dataKey): self
  {
    unset($this->data[$dataKey]);

    return $this;
  }

  public function getDataValue(string $dataKey): mixed
  {
    return isset($this->data[$dataKey]) ? $this->data[$dataKey]->getValue() : null;
  }


  public function __toString(): string
  {
    return join(" ", $this->data);
  }
}
