<?php

// src/Service/SlotTimeHelper.php
namespace App\Service;

class DateTimeHelper
{
    public function roundUpToNextSlot(\DateTimeInterface $dateTime): \DateTime
    {
        $minutes = (int) $dateTime->format('i');
        $rounded = new \DateTime($dateTime->format('Y-m-d H:i:s'), $dateTime->getTimezone());

        if ($minutes === 0 || $minutes === 30) {
            $rounded->setTime((int)$rounded->format('H'), $minutes, 0);
            return $rounded;
        }

        if ($minutes < 30) {
            $rounded->setTime((int)$rounded->format('H'), 30, 0);
        } else {
            $rounded->modify('+1 hour')->setTime((int)$rounded->format('H'), 0, 0);
        }

        return $rounded;
    }
}