<?php

namespace adrienpayet\comments;
use adrienpayet\D2P\data\location\Location;
use adrienpayet\D2P\data\Author;
use adrienpayet\D2P\data\Position;

class BaseComment {
  protected Location $location;
  protected Author $author;
  protected string $text;
  protected string $date;
  protected string $id;
  protected ?Position $position = null;

  public function __construct($data) {
    $this->location = new Location($data["location"]);
    $this->text = $data["text"];
    $this->author = new Author($data["author"]);
    $this->date = $data["date"];
    $this->id = $data["id"];
    $this->position = new Position($data['position']);
  }
  
  public function toArray() {
    return [
        "location" => $this->location->toArray(),
        "position" => $this->position->toArray(),
        "text" => $this->text,
        "author" => $this->author->toArray(),
        "date" => $this->date,
        "id" => $this->id,
    ];
  }
}
