<?php

namespace adrienpayet\D2P\data;

class Position
{
    public ?int $pageIndex = null;
    public ?float $x = null;
    public ?float $y = null;

    public function __construct(array $data)
    {
        if (isset($data["pageIndex"])) {
            $this->pageIndex = $data['pageIndex'];
        }
        if (isset($data["x"])) {
            $this->x = (float) $data['x'];
            $this->y = (float) $data['y'];
        }
    }

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

        if ($this->pageIndex) {
            $array["pageIndex"] = $this->pageIndex;
        }

        if ($this->x) {
            $array["x"] = $this->x;
            $array["y"] = $this->y;
        }

        return $array;
    }
}
