<?php
/**
 * Activation tasks.
 *
 * @package CertaCart_EU_Product_Readiness
 */

namespace CertaCart\EU_Product_Readiness;

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

final class Activator {
	public static function activate( bool $network_wide = false ): void {
		if ( is_multisite() && $network_wide ) {
			$site_ids = get_sites( array( 'fields' => 'ids', 'number' => 0 ) );
			foreach ( $site_ids as $site_id ) {
				switch_to_blog( (int) $site_id );
				self::activate_site();
				restore_current_blog();
			}
			return;
		}
		self::activate_site();
	}

	private static function activate_site(): void {
		Schema::install();
		Settings::seed_defaults();
		Cleanup::schedule();
		update_option( 'ccpr_version', CCPR_VERSION, false );
		set_transient( 'ccpr_activation_redirect', 1, 60 );
	}
}
