<?php
/**
 * Privacy class for Voice Logica AI for WooCommerce plugin
 *
 * @package VoiceLogica_AI_WooCommerce
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Class VoiceLogica_AI_Privacy
 */
class VoiceLogica_AI_Privacy {

	/**
	 * Constructor
	 */
	public function __construct() {
		add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ) );
		add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ) );
		add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) );
	}

	/**
	 * Register data exporters
	 *
	 * @param array $exporters Existing exporters.
	 * @return array
	 */
	public function register_exporters( $exporters ) {
		$exporters['voicelogica-ai-for-woocommerce'] = array(
			'exporter_friendly_name' => __( 'Voice Logica AI for WooCommerce', 'voicelogica-ai-for-woocommerce' ),
			'callback'               => array( $this, 'export_data' ),
		);
		return $exporters;
	}

	/**
	 * Export plugin data (minimal - we don't store personal data, but API key is site-level)
	 *
	 * @param string $email_address User email.
	 * @param int    $page          Page number.
	 * @return array
	 */
	public function export_data( $email_address, $page = 1 ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Required by WP_Privacy_Exporter callback signature.
		return array(
			'data' => array(),
			'done' => true,
		);
	}

	/**
	 * Register data erasers
	 *
	 * @param array $erasers Existing erasers.
	 * @return array
	 */
	public function register_erasers( $erasers ) {
		$erasers['voicelogica-ai-for-woocommerce'] = array(
			'eraser_friendly_name' => __( 'Voice Logica AI for WooCommerce', 'voicelogica-ai-for-woocommerce' ),
			'callback'             => array( $this, 'erase_data' ),
		);
		return $erasers;
	}

	/**
	 * Erase plugin data for a user (we don't store per-user data)
	 *
	 * @param string $email_address User email.
	 * @param int    $page          Page number.
	 * @return array
	 */
	public function erase_data( $email_address, $page = 1 ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Required by WP_Privacy_Eraser callback signature.
		return array(
			'items_removed'  => 0,
			'items_retained' => 0,
			'messages'       => array(),
			'done'           => true,
		);
	}

	/**
	 * Add privacy policy suggestion
	 */
	public function add_privacy_policy_content() {
		if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
			return;
		}

		wp_add_privacy_policy_content(
			__( 'Voice Logica AI for WooCommerce', 'voicelogica-ai-for-woocommerce' ),
			__(
				'When this plugin is connected to Voice Logica AI, order and customer data may be sent to Voice Logica AI, and Voice Logica AI may create or update orders and customers in your store. Please refer to Voice Logica AI\'s privacy policy for how they handle this data.',
				'voicelogica-ai-for-woocommerce'
			)
		);
	}
}
