<?php
/**
 * Business Service Provider
 *
 * Registers business logic services in the container
 *
 * @package NemtlyBooking
 * @since   PBOOKING_SINCE
 */

namespace NemtlyBooking\Providers;

use NemtlyBooking\Core\Service_Provider;
use NemtlyBooking\Core\Container;
use NemtlyBooking\Services\Event_Service;
use NemtlyBooking\Services\Booking_Service;
use NemtlyBooking\Services\Notification_Service;
use NemtlyBooking\Services\Email_Notification_Service;
use NemtlyBooking\Services\Event_Types_Service;
use NemtlyBooking\Services\Settings_Service;
use NemtlyBooking\Services\Slot_Service;
use NemtlyBooking\Services\Recurrence_Calculator;
use NemtlyBooking\Subscribers\Booking_Payment_Subscriber;

/**
 * Business Service Provider class
 *
 * @since PBOOKING_SINCE
 */
class Business_Service_Provider extends Service_Provider {

    /**
     * Register business services
     *
     * @since PBOOKING_SINCE
     *
     * @param Container $container The dependency injection container.
     */
    public function register( Container $container ) {
        // Event Service
        $container->register(
            'event_service',
            function ( $container ) {
                return new Event_Service(
                    $container->get( 'event_repository' ),
                    $container->get( 'event_manager' )
                );
            }
        );

        // Booking Service
        $container->register(
            'booking_service',
            function ( $container ) {
                return new Booking_Service(
                    $container->get( 'booking_repository' ),
                    $container->get( 'event_repository' ),
                    $container->get( 'event_manager' )
                );
            }
        );

        // Notification Service
        $container->register(
            'notification_service',
            function ( $container ) {
                return new Notification_Service( $container->get( 'event_manager' ) );
            }
        );

        // Email Notification Service
        $container->register(
            'email_notification_service',
            function ( $container ) {
                return new Email_Notification_Service(
                    $container->get( 'event_repository' ),
                    $container->get( 'event_manager' )
                );
            }
        );

        // Event Types Service
        $container->register(
            'event_types_service',
            function () {
                return new Event_Types_Service();
            }
        );

        // Settings Service
        $container->register(
            'settings_service',
            function () {
                return new Settings_Service();
            }
        );

        // Recurrence Calculator
        $container->register(
            'recurrence_calculator',
            function () {
                return new Recurrence_Calculator();
            }
        );

        // Slot Service
        $container->register(
            'slot_service',
            function ( $container ) {
                return new Slot_Service(
                    $container->get( 'booking_repository' ),
                    $container->get( 'event_repository' ),
                    $container->get( 'recurrence_calculator' )
                );
            }
        );

        // Booking Payment Subscriber
        $container->register(
            'booking_payment_subscriber',
            function ( $container ) {
                return new Booking_Payment_Subscriber(
                    $container->get( 'booking_repository' )
                );
            }
        );

        $this->mark_registered();
    }

    /**
     * Boot services
     *
     * @since PBOOKING_SINCE
     *
     * @param Container $container The dependency injection container.
     */
    public function boot( Container $container ) {
        $subscriber = $container->get( 'booking_payment_subscriber' );
        $subscriber->register();

        $this->mark_booted();
    }
}
