<?php

namespace Cart\notify;

use Cart\notify\Frontend\NotificationData;
use Cart\notify\Settings\Repository;
use Cart\notify\WooCommerce\Compatibility;
use Cart\notify\WooCommerce\Integration;

defined( 'ABSPATH' ) || exit;

/**
 * Plugin runtime bootstrap.
 */
class Plugin {
	/**
	 * Bootstrapped service instances.
	 *
	 * @var array
	 */
	private $services = array();

	/**
	 * Start plugin services.
	 *
	 * @return void
	 */
	public function boot() {
		$this->load_helpers();

		$necessary = new Necessary();
		$settings  = new Repository();
		$wc        = new Integration();
		$data      = new NotificationData( $settings );

		$this->services['necessary'] = $necessary;
		$this->services['settings']  = $settings;
		$this->services['wc']        = $wc;
		$this->services['data']      = $data;

		$this->services['compatibility'] = new Compatibility();
		$this->services['assets']        = new Assets( $settings, $wc, $data );

		if ( ! $necessary->is_woocommerce_active() ) {
			if ( is_admin() ) {
				$this->services['admin'] = new Admin();
			}
			return;
		}

		if ( is_admin() ) {
			$this->services['admin'] = new Admin();
		} else {
			$this->services['frontend'] = new Frontend( $wc );
		}
	}

	/**
	 * Load procedural helpers before service wiring.
	 *
	 * @return void
	 */
	private function load_helpers() {
		if ( file_exists( CART_NOTIFY_INCLUDES . '/functions.php' ) ) {
			require_once CART_NOTIFY_INCLUDES . '/functions.php';
		}
	}
}

