<?php
/**
 * Plugin Deactivator for HVAC Community Events
 *
 * Handles plugin deactivation tasks
 *
 * @package HVAC_Community_Events
 * @since 1.0.0
 */

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

/**
 * HVAC_Deactivator class
 */
class HVAC_Deactivator {
    
    /**
     * Deactivate the plugin
     * 
     * @return void
     */
    public static function deactivate() {
        HVAC_Logger::info('Starting plugin deactivation', 'Deactivator');
        
        // Clear scheduled cron jobs
        self::clear_cron_jobs();
        
        // Deactivate announcements system
        if (class_exists('HVAC_Announcements_Manager')) {
            HVAC_Announcements_Manager::deactivate();
        }
        
        // Flush rewrite rules
        flush_rewrite_rules();
        
        HVAC_Logger::info('Plugin deactivation completed', 'Deactivator');
    }
    
    /**
     * Clear scheduled cron jobs
     * 
     * @return void
     */
    private static function clear_cron_jobs() {
        // Clear daily trainer status check
        $timestamp = wp_next_scheduled('hvac_daily_trainer_status_check');
        if ($timestamp) {
            wp_unschedule_event($timestamp, 'hvac_daily_trainer_status_check');
            HVAC_Logger::info('Cleared daily trainer status check cron', 'Deactivator');
        }
        
        // Clear weekly cleanup
        $timestamp = wp_next_scheduled('hvac_weekly_cleanup');
        if ($timestamp) {
            wp_unschedule_event($timestamp, 'hvac_weekly_cleanup');
            HVAC_Logger::info('Cleared weekly cleanup cron', 'Deactivator');
        }
    }
}