<?php
/**
 * Pending Reward Service.
 *
 * Lite stub: Pending rewards functionality is a Pro feature (Free Product rewards).
 * This stub provides safe default returns for Lite users.
 *
 * @package RewardsWP
 * @since 1.2.0
 */

namespace Awesomemotive\Rewardswp\Services;

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

use Awesomemotive\Rewardswp\Interfaces\IntegrationInterface;

/**
 * Class PendingRewardService
 *
 * Lite stub for pending reward service. Returns safe defaults.
 * Full implementation is in Pro/Services/ProPendingRewardService.
 *
 * @since 1.2.0
 */
class PendingRewardService {

	/**
	 * Constructor.
	 *
	 * @since 1.2.0
	 *
	 * @param IntegrationInterface $integration     Active integration instance.
	 * @param RewardsService       $rewards_service Rewards service instance.
	 */
	public function __construct(
		IntegrationInterface $integration,
		RewardsService $rewards_service
	) {
		// Lite stub: No initialization needed.
	}

	/**
	 * Set a pending reward in the session.
	 *
	 * Lite stub: Always returns false.
	 *
	 * @since 1.2.0
	 *
	 * @param int    $reward_id   The reward ID.
	 * @param int    $product_id  The free product ID.
	 * @param string $coupon_code The coupon code for this reward.
	 * @param float  $min_spend   The minimum spend required.
	 *
	 * @return bool Always false in Lite.
	 */
	public function set_pending_reward( int $reward_id, int $product_id, string $coupon_code, float $min_spend ): bool {
		return false;
	}

	/**
	 * Get the current pending reward data.
	 *
	 * Lite stub: Always returns null.
	 *
	 * @since 1.2.0
	 *
	 * @return array|null Always null in Lite.
	 */
	public function get_pending_reward(): ?array {
		return null;
	}

	/**
	 * Clear the pending reward from session.
	 *
	 * Lite stub: Always returns true.
	 *
	 * @since 1.2.0
	 *
	 * @return bool Always true in Lite.
	 */
	public function clear_pending_reward(): bool {
		return true;
	}

	/**
	 * Set a reward as dismissed in the session.
	 *
	 * Lite stub: Always returns false.
	 *
	 * @since 1.2.0
	 *
	 * @param int $reward_id The reward ID to dismiss.
	 *
	 * @return bool Always false in Lite.
	 */
	public function set_dismissed_reward( int $reward_id ): bool {
		return false;
	}

	/**
	 * Get the currently dismissed reward ID.
	 *
	 * Lite stub: Always returns null.
	 *
	 * @since 1.2.0
	 *
	 * @return int|null Always null in Lite.
	 */
	public function get_dismissed_reward(): ?int {
		return null;
	}

	/**
	 * Clear the dismissed reward from session.
	 *
	 * Lite stub: Always returns true.
	 *
	 * @since 1.2.0
	 *
	 * @return bool Always true in Lite.
	 */
	public function clear_dismissed_reward(): bool {
		return true;
	}

	/**
	 * Check if a reward is dismissed.
	 *
	 * Lite stub: Always returns false.
	 *
	 * @since 1.2.0
	 *
	 * @param int $reward_id The reward ID to check.
	 *
	 * @return bool Always false in Lite.
	 */
	public function is_reward_dismissed( int $reward_id ): bool {
		return false;
	}

	/**
	 * Calculate cart eligibility for the pending reward.
	 *
	 * Lite stub: Returns default not-eligible state.
	 *
	 * @since 1.2.0
	 *
	 * @param array|null $pending_data Optional pending data.
	 *
	 * @return array Default not-eligible state.
	 */
	public function calculate_eligibility( ?array $pending_data = null ): array {
		return [
			'is_eligible'       => false,
			'cart_subtotal'     => 0.0,
			'eligible_subtotal' => 0.0,
			'min_spend'         => 0.0,
			'remaining'         => 0.0,
			'product_in_cart'   => false,
		];
	}

	/**
	 * Attempt to apply the pending reward if eligible.
	 *
	 * Lite stub: Returns no-pending state.
	 *
	 * @since 1.2.0
	 *
	 * @return array No-pending state.
	 */
	public function maybe_apply_pending_reward(): array {
		return [
			'applied' => false,
			'message' => '',
			'state'   => 'no_pending',
		];
	}

	/**
	 * Handle cart dropping below minimum spend after reward was applied.
	 *
	 * Lite stub: Always returns false.
	 *
	 * @since 1.2.0
	 *
	 * @param int    $reward_id   The reward ID.
	 * @param string $coupon_code The coupon code.
	 * @param int    $product_id  The free product ID.
	 * @param float  $min_spend   The minimum spend requirement.
	 *
	 * @return bool Always false in Lite.
	 */
	public function handle_drop_below_minimum( int $reward_id, string $coupon_code, int $product_id, float $min_spend ): bool {
		return false;
	}

	/**
	 * Get pending reward status for display in the UI.
	 *
	 * Lite stub: Returns default no-pending state.
	 *
	 * @since 1.2.0
	 *
	 * @return array Default no-pending state.
	 */
	public function get_status(): array {
		return [
			'has_pending'     => false,
			'reward_id'       => null,
			'product_id'      => null,
			'min_spend'       => 0.0,
			'remaining'       => 0.0,
			'is_eligible'     => false,
			'product_in_cart' => false,
			'coupon_applied'  => false,
		];
	}

	/**
	 * Check eligibility for a free product reward and set as pending if not eligible.
	 *
	 * Lite stub: Always returns null (Free Product is a Pro feature).
	 *
	 * @since 1.2.0
	 *
	 * @param int                  $reward_id   The reward ID.
	 * @param string               $coupon_code The coupon code.
	 * @param IntegrationInterface $integration The integration instance.
	 *
	 * @return array|null Always null in Lite.
	 */
	public function check_eligibility_and_set_pending( int $reward_id, string $coupon_code, IntegrationInterface $integration ): ?array {
		return null;
	}
}
