<?php
/**
 * BookiFlex Notification Extension
 *
 * @package    BookiFlex
 * @subpackage Notification
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */


declare(strict_types=1);
namespace BookiFlex\Extensions\Notification\Service;

use BookiFlex\Core\Model\Reservation\Event\ReservationStatusWasChanged;
use BookiFlex\Core\Model\Reservation\Event\ReservationWasCreated;
use BookiFlex\Core\Model\Reservation\ReservationStatus;
use BookiFlex\Extensions\Notification\Model\NotificationEvent;

defined( 'ABSPATH' ) || exit;

class EventNormalizer
{
    public function fromDomainEvent(object $event): array
    {
        return match (true) {
            $event instanceof ReservationWasCreated       => [NotificationEvent::NewReservation],
            $event instanceof ReservationStatusWasChanged => $this->normalizeStatusChange($event),
            default                                       => [],
        };
    }

    private function normalizeStatusChange(ReservationStatusWasChanged $event): array
    {
        return match ($event->getTo()) {
            ReservationStatus::STATUS_CONFIRMED       => [NotificationEvent::ReservationConfirmed],
            ReservationStatus::STATUS_CANCELLED       => [NotificationEvent::ReservationCancelled],
            ReservationStatus::STATUS_OVERDUE         => [NotificationEvent::ReservationOverdue],
            ReservationStatus::STATUS_WAITING_PAYMENT => [NotificationEvent::WaitingConfirmation],
            default                                   => [],
        };
    }
}
