<?php

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

class YATOON_Deactivator {

    public static function deactivate() {
        // Unschedule tasks
        $timestamp = wp_next_scheduled('yatoon_sync_square_data');
        if ($timestamp) {
            wp_unschedule_event($timestamp, 'yatoon_sync_square_data');
        }
        $waitlist_timestamp = wp_next_scheduled('yatoon_check_waitlist_availability');
        if ($waitlist_timestamp) {
            wp_unschedule_event($waitlist_timestamp, 'yatoon_check_waitlist_availability');
        }

        wp_clear_scheduled_hook( 'yatoon_woocommerce_cleanup' );
        wp_clear_scheduled_hook( 'yatoon_woocommerce_legacy_option_cleanup' );
        wp_clear_scheduled_hook( 'yatoon_prune_funnel_events' );
        delete_transient( 'yatoon_woocommerce_cleanup_schedule_checked' );
        if ( function_exists( 'as_unschedule_all_actions' ) ) {
            as_unschedule_all_actions( 'yatoon_woocommerce_cleanup', array(), 'yatoon' );
            as_unschedule_all_actions( 'yatoon_woocommerce_legacy_option_cleanup', array(), 'yatoon' );
        }

        // Flush rewrite rules
        flush_rewrite_rules();
    }
}
