<?php
/**
 * CustomerRegisteredRule — context has a WordPress user ID vs guest-only context.
 *
 * @package CartCue\Rules
 */

namespace CartCue\Rules;

defined( 'ABSPATH' ) || exit;

class CustomerRegisteredRule extends AbstractRule {

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

	public function get_label(): string {
		return __( 'Customer account status', 'cartcue-sales-automation' );
	}

	public function get_operators(): array {
		return [
			'is_registered' => __( 'has a registered account', 'cartcue-sales-automation' ),
			'is_guest'      => __( 'is a guest (no user ID)', 'cartcue-sales-automation' ),
		];
	}

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

	public function evaluate( array $config, array $data ): bool {
		$cid = (int) ( $data['customer_id'] ?? 0 );
		$op  = $config['operator'] ?? 'is_registered';

		if ( 'is_guest' === $op ) {
			return $cid < 1;
		}
		return $cid > 0;
	}
}
