<?php
namespace TeknoTok\AiTranslator\Utils;

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

/**
 * Utility class to handle cache purging across common WordPress caching plugins.
 */
class CacheManager {
	/**
	 * Purge the cache for a specific post/product.
	 *
	 * @param int $post_id Post ID.
	 * @return void
	 */
	public static function purge_post_cache( $post_id ) {
		if ( ! $post_id ) {
			return;
		}

		// LiteSpeed Cache integration
		if ( function_exists( 'litespeed_clean_post' ) ) {
			litespeed_clean_post( $post_id );
		}

		// WP Super Cache integration
		if ( function_exists( 'wpsc_delete_post_cache' ) ) {
			wpsc_delete_post_cache( $post_id );
		}

		// W3 Total Cache integration
		if ( function_exists( 'w3tc_flush_post' ) ) {
			w3tc_flush_post( $post_id );
		}

		// WP Rocket integration
		if ( function_exists( 'rocket_clean_post' ) ) {
			rocket_clean_post( $post_id );
		}

		// SG Optimizer (SiteGround) integration
		if ( class_exists( '\SG_CachePress_Supercacher' ) && method_exists( '\SG_CachePress_Supercacher', 'purge_post' ) ) {
			\SG_CachePress_Supercacher::purge_post( $post_id );
		}

		// Autoptimize integration
		if ( class_exists( '\autoptimizeCache' ) && method_exists( '\autoptimizeCache', 'clearall' ) ) {
			\autoptimizeCache::clearall();
		}

		// General WordPress standard clean cache action
		clean_post_cache( $post_id );
	}
}
