38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Event\Services;
|
|
|
|
use App\Domains\Event\Enums\EventDateChangeType;
|
|
use App\Domains\Event\Models\EventDate;
|
|
use App\Domains\Event\Models\EventDateChange;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class EventDateInfoFormatter
|
|
{
|
|
/** @param Collection<int, EventDateChange> $changes */
|
|
public function format(EventDate $eventDate, Collection $changes): ?string
|
|
{
|
|
$messages = collect();
|
|
|
|
if ($eventDate->suspended_at !== null) {
|
|
$messages->push('Esta fecha fue cancelada.');
|
|
}
|
|
|
|
$sourceDates = $changes
|
|
->where('change_type', EventDateChangeType::Rescheduled)
|
|
->where('destination_event_date_id', $eventDate->getKey())
|
|
->pluck('previous_date')
|
|
->filter()
|
|
->map(fn ($date): string => $date->format('d/m/Y'))
|
|
->unique()
|
|
->values();
|
|
|
|
if ($sourceDates->isNotEmpty()) {
|
|
$verb = $sourceDates->count() === 1 ? 'se reprogramó' : 'se reprogramaron';
|
|
$messages->push("{$sourceDates->join(', ', ' y ')} {$verb} para este día.");
|
|
}
|
|
|
|
return $messages->isEmpty() ? null : $messages->join(' ');
|
|
}
|
|
}
|