<?php

namespace App\Services\Sync;

use Carbon\CarbonImmutable;

class DateRangeResolver
{
    public function resolve(?string $from = null, ?string $to = null): array
    {
        $end = $to ? CarbonImmutable::parse($to)->startOfDay() : now()->subDay()->toImmutable()->startOfDay();
        $start = $from ? CarbonImmutable::parse($from)->startOfDay() : $end;

        if ($start->greaterThan($end)) {
            throw new \InvalidArgumentException('Başlangıç tarihi bitiş tarihinden büyük olamaz.');
        }

        return [$start->toDateString(), $end->toDateString()];
    }
}
