<?php
/**
 * Main plugin bootstrap.
 *
 * @package FailedOrderRescueForWooCommerce
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class FORD_Plugin {
	/**
	 * Singleton instance.
	 *
	 * @var FORD_Plugin|null
	 */
	private static $instance = null;

	/**
	 * Get singleton.
	 *
	 * @return FORD_Plugin
	 */
	public static function instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Set defaults on activation.
	 *
	 * @return void
	 */
	public static function activate() {
		if ( ! get_option( 'ford_settings' ) ) {
			add_option( 'ford_settings', FORD_Settings::defaults() );
		}
	}

	/**
	 * Initialize runtime.
	 *
	 * @return void
	 */
	public function init() {
		FORD_Settings::init();

		if ( ! class_exists( 'WooCommerce' ) ) {
			add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
			return;
		}

		FORD_Email::init();
		FORD_Orders::init();
		FORD_Pro::init();

		if ( is_admin() ) {
			FORD_Admin::init();
		}
	}

	/**
	 * WooCommerce dependency notice.
	 *
	 * @return void
	 */
	public function woocommerce_missing_notice() {
		if ( ! current_user_can( 'activate_plugins' ) ) {
			return;
		}

		echo '<div class="notice notice-error"><p>';
		echo esc_html__( 'Failed Order Rescue for WooCommerce requires WooCommerce to be installed and active.', 'failed-order-rescue-for-woocommerce' );
		echo '</p></div>';
	}
}
