<?php
/**
 * OrderGuestRule — guest checkout vs registered customer on the order.
 *
 * @package CartCue\Rules
 */

namespace CartCue\Rules;

defined( 'ABSPATH' ) || exit;

class OrderGuestRule extends AbstractRule {

	public function get_slug(): string {
		return 'order_is_guest';
	}

	public function get_label(): string {
		return __( 'Order Placed By', 'cartcue-sales-automation' );
	}

	public function get_operators(): array {
		return [
			'is_guest'      => __( 'guest checkout', 'cartcue-sales-automation' ),
			'is_registered' => __( 'registered customer', 'cartcue-sales-automation' ),
		];
	}

	public function get_value_type(): string {
		return 'hidden';
	}

	public function evaluate( array $config, array $data ): bool {
		$order_id = (int) ( $data['order_id'] ?? 0 );
		if ( ! $order_id ) {
			return true;
		}

		$order = wc_get_order( $order_id );
		if ( ! $order ) {
			return false;
		}

		$is_guest = 0 === (int) $order->get_customer_id();
		$op       = $config['operator'] ?? 'is_guest';

		if ( 'is_registered' === $op ) {
			return ! $is_guest;
		}
		return $is_guest;
	}
}
