<?php

namespace Licenzo\Modules\EDD;

use Licenzo\Helper\Settings;

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

class EDD
{
    public static function bootstrap(): void
    {
        EddRecurringDetector::registerAdminNotice();
        EddGatewayNotice::register();

        if (EddRecurringDetector::hasBlockingConflict()) {
            return;
        }

        (new EddOrderHandler())->handle();
        (new EddStripeCompatibilityService())->register();
        (new EddCheckoutPolicyService())->register();
        (new EddPriceDisplayService())->register();
        (new EddProductMappingService())->register();
        EddEmailService::register();
    }

    public static function init(): void
    {
        $settings = Settings::getGeneralSettings();

        if (EddRecurringDetector::hasBlockingConflict()) {
            return;
        }

        if (($settings['enable_edd_purchase_history'] ?? 'yes') === 'yes') {
            EddPurchaseHistoryService::register();
        }
    }
}
