<?php
/**
 * Recent-sale order eligibility.
 *
 * @package VoidPulse
 */

namespace VoidPulse\Notifications;

defined( 'ABSPATH' ) || exit;

final class OrderEligibility {
	/**
	 * Determine whether an order is safe and eligible.
	 *
	 * @param \WC_Order          $order Order.
	 * @param array<string,mixed> $settings Order settings.
	 * @return bool
	 */
	public function is_eligible( $order, $settings ) {
		if ( ! $order instanceof \WC_Order ) {
			return false;
		}
		$status = 'wc-' . $order->get_status();
		if ( ! in_array( $status, (array) $settings['statuses'], true ) ) {
			return false;
		}
		if ( in_array( $order->get_status(), array( 'refunded', 'failed', 'cancelled', 'pending', 'on-hold', 'checkout-draft', 'trash' ), true ) ) {
			return false;
		}
		if ( ! $settings['include_guests'] && 0 === (int) $order->get_customer_id() ) {
			return false;
		}
		if ( (float) $order->get_total_refunded() >= (float) $order->get_total() && (float) $order->get_total() > 0 ) {
			return false;
		}
		return (bool) apply_filters( 'voidpulse_order_is_eligible', true, $order, $settings );
	}
}
