<?php
/**
 * Author: Rymera Web Co
 *
 * @package SAAI\Actions
 */

namespace SAAI\Actions;

use SAAI\Abstracts\Abstract_Class;

/**
 * Deactivation class.
 *
 * @since 1.0.0
 */
class Deactivation extends Abstract_Class {

    /**
     * Holds boolean value whether the plugin is being activated network wide.
     *
     * @var bool
     */
    protected $network_wide;

    /**
     * Constructor.
     *
     * @param bool $network_wide Whether the plugin is being activated network wide.
     */
    public function __construct( $network_wide = false ) {

        $this->network_wide = $network_wide;
    }

    /**
     * Run plugin deactivation actions.
     */
    public function run() {
        $this->unschedule_tasks();
    }

    /**
     * Unschedule all tasks when plugin is deactivated.
     *
     * @return void
     */
    private function unschedule_tasks() {
        // Unschedule Plan Manager tasks.
        $plan_manager = \SAAI\Classes\Plan_Manager::instance();
        if ( $plan_manager ) {
            $plan_manager->unschedule_tasks();
        }

        // Unschedule Product Description AI tasks.
        $product_description_automations = \SAAI\Automations\Product_Description_Automations::instance();
        if ( $product_description_automations ) {
            $product_description_automations->unschedule_main_description_length_check();
        }

        // Unschedule Product Summaries AI tasks.
        $product_summaries_automations = \SAAI\Automations\Product_Summaries_Automations::instance();
        if ( $product_summaries_automations ) {
            $product_summaries_automations->unschedule_missing_short_description_check();
        }
    }
}
