<?php

namespace App\Libs;

use DateInterval;
use DateTime;

class Route
{
    private float $distance;

    private float $duration;

    private array $geometry;

    public function __construct(
        object $route
    ) {
        $this->distance = $route->results[0]->distance;
        $this->duration = $route->results[0]->time;
        $this->geometry = $route->results[0]->geometry[0];
    }

    public function getDuration(): ?DateInterval
    {
        $startDate = new DateTime("@0");
        $endDate = new DateTime("@{$this->duration}");
        $dur = $startDate->diff($endDate);

        return $dur;
    }

    public function getDurationString(): string
    {
        return $this->getDuration()->format('%H:%I:%S');
    }

    public function getDistance(): float
    {
        return $this->distance;
    }

    public function getGeometry(): array
    {
        return $this->geometry;
    }
}
