<?php

declare(strict_types=1);

namespace BookiFlex\Extensions\NotificationPreview;

use BookiFlex\Core\Contract\Payment\PaymentAllocationProviderInterface;
use BookiFlex\Core\Service\Reservation\ReservationDetails;
use BookiFlex\Extensions\Notification\Provider\CoreNotificationEventProvider;
use BookiFlex\Extensions\Notification\Provider\NotificationContextProvider;
use BookiFlex\Extensions\Notification\Service\NotificationRenderer;
use BookiFlex\Extensions\NotificationPreview\Api\Controller\NotificationPreviewController;
use BookiFlex\Extensions\NotificationPreview\Repository\FakeAccommodationTypeRepository;
use BookiFlex\Extensions\NotificationPreview\Repository\FakeRatePlanRepository;
use BookiFlex\Extensions\NotificationPreview\Repository\FakeReservationRepository;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

defined( 'ABSPATH' ) || exit;

class ServiceProvider implements ServiceProviderInterface
{
    public function register(Container $pimple): void
    {
        $pimple['fake.notification.data'] = function ($c) {
            $provider = new NotificationContextProvider(
                new ReservationDetails(
                    new FakeReservationRepository(),
                    new FakeRatePlanRepository(),
                    new FakeAccommodationTypeRepository(),
                    $c->get(PaymentAllocationProviderInterface::class)
                ),
                $c->get('config'),
            );
            $provider->addEventProvider($c->get(CoreNotificationEventProvider::class));

            return $provider;
        };

        $pimple[NotificationPreviewController::class] = function ($c) {
            return new NotificationPreviewController(
                $c->get(NotificationRenderer::class),
                $c->get('fake.notification.data'),
            );
        };
    }
}