<?php
/**
 * Plugin deactivation handler.
 */

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

class ZINV_Deactivator {

    public static function deactivate(): void {
        // Flush WP cron events for this plugin.
        wp_clear_scheduled_hook( 'zinv_daily_tasks' );
        wp_clear_scheduled_hook( 'zinv_hourly_tasks' );
        wp_clear_scheduled_hook( 'zinv_weekly_tasks' );

        // Clear Action Scheduler jobs if the function exists.
        if ( function_exists( 'as_unschedule_all_actions' ) ) {
            as_unschedule_all_actions( 'zinv_subscription_billing' );
            as_unschedule_all_actions( 'zinv_overdue_detection' );
            as_unschedule_all_actions( 'zinv_dunning_steps' );
            as_unschedule_all_actions( 'zinv_summary_refresh' );
            as_unschedule_all_actions( 'zinv_estimate_expiry' );
            as_unschedule_all_actions( 'zinv_webhook_retries' );
            as_unschedule_all_actions( 'zinv_activity_archival' );
            as_unschedule_all_actions( 'zinv_monthly_summaries' );
        }

        delete_transient( 'zinv_dashboard_kpis' );
        delete_transient( 'zinv_dash_monthly_revenue' );
        delete_transient( 'zinv_dash_pending_invoices' );

        flush_rewrite_rules( false );
    }
}

