<?php

declare(strict_types=1);

namespace BookiFlex\Extensions\Notification\Api\Transformer;

use BookiFlex\Extensions\Notification\Model\Notification;

defined( 'ABSPATH' ) || exit;

class NotificationTransformer
{
    public function transform(Notification $notification): array
    {
        return [
            'sid'         => $notification->getSid(),
            'event'       => $notification->getEvent(),
            'stakeholder' => $notification->getStakeholder()->value,
            'status'      => (string) $notification->getStatus(),
            'sendTo'      => $notification->getSendTo(),
            'sendTime'    => $notification->getSendTime()?->format('Y-m-d H:i:s'),
            'transport'   => $notification->getTransport(),
            'attempts'    => $notification->getAttempts(),
            'hasSnapshot' => $notification->hasSnapshot(),
            'createdAt'   => $notification->getCreatedAt()?->format('Y-m-d H:i:s'),
            'updatedAt'   => $notification->getUpdatedAt()?->format('Y-m-d H:i:s'),
        ];
    }

    /**
     * @param Notification[] $notifications
     * @return array
     */
    public function transformCollection(array $notifications): array
    {
        return array_map(
            fn(Notification $notification) => $this->transform($notification),
            $notifications
        );
    }
}