<?php
/**
 * Deactivator Class File
 *
 * This class defines tasks that must be run when the plugin is deactivated.
 */

namespace CarDealerPress\Includes\Uninstall;

use CarDealerPress\Includes\Cron\Cron;
use CarDealerPress\includes\functions\Logger;
use function CarDealerPress\get_blog_ids;

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

class Deactivator {
	use Logger;
	public function deactivate( $network_wide ) {
		if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) {
			// @codingStandardsIgnoreStart
			error_log('CDP Message: Multisite deactivated and networkwide');
			// @codingStandardsIgnoreEnd
			if ( ! is_super_admin() ) {
				return;
			}
			$sites = get_sites();
			foreach ( $sites as $site ) {
				$blog_id = $site->blog_id;
				switch_to_blog( $blog_id );
				( new Cron() )->remove_cron_schedule();
				flush_rewrite_rules();
				$this->append_log( array( 'message' => "CDP Message: CarDealerPress has been deactivated, on site id: $blog_id" ) );
				// @codingStandardsIgnoreStart
				error_log( "CDP Message: CarDealerPress MultiSite has been deactivated, on site id: $blog_id" );
				// @codingStandardsIgnoreEnd
				restore_current_blog();
			}
		} else {
			if ( ! current_user_can( 'activate_plugins' ) ) {
				return;
			}
			$blog_id = get_current_blog_id();
			// @codingStandardsIgnoreStart
			error_log( 'Single Plugin is de-activated on site id: ' . $blog_id );
			// @codingStandardsIgnoreEnd
		}
	}

	/**
	 * Register user who deactivates the plugin
	 */
	public function register_deactivator_user() {
		$current_user = $this->get_this_login_user();

	}

	private function get_this_login_user() {
		// Implement the logic to get the current logged-in user object.
		// Replace the following line with your implementation.
		$current_user = wp_get_current_user();

		return $current_user;
	}

}
