<?php

/**
 * Handles package activation and deactivation.
 *
 * @package northmill-online-shared
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Sync\Northmill_Online_Shared\Modules;

use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Abstract_Shared_Base;
use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Helpers\Hook_Helpers;
defined('ABSPATH') || exit;
/**
 * Class Package_Activation_Module
 */
class Package_Activation_Module extends Abstract_Module
{
    const ACTION_ACTIVATION_CRON_CHECKER = 'northmill_online_shared_package_activation_cron_checker';
    /**
     * Package_Activation_Module constructor.
     *
     * @param Abstract_Shared_Base $shared Shared instance.
     */
    final public function __construct(Abstract_Shared_Base $shared)
    {
        parent::__construct($shared);
        add_action(self::ACTION_ACTIVATION_CRON_CHECKER, array($this, 'package_activation_cron_checker'));
    }
    /**
     * Run on package activation.
     */
    final public function package_activation(): void
    {
        wp_schedule_single_event(time() + 5, self::ACTION_ACTIVATION_CRON_CHECKER);
        Hook_Helpers::do_scoped_action('northmill_online_shared_package_activation');
    }
    /**
     * Run the package activation cron checker.
     */
    final public function package_activation_cron_checker(): void
    {
        Abstract_Shared_Base::base_instance()->logger->log('activation', 'Running cron checker on package activation');
        $this->shared->cron->check_event_statuses();
    }
    /**
     * Run on package deactivation.
     */
    final public function package_deactivation(): void
    {
        $this->shared->cron->deactivate();
        Hook_Helpers::do_scoped_action('northmill_online_shared_package_deactivation');
    }
}
