<?php

namespace AutomateWoo\Rules;

use AutomateWoo\Logic_Helper;

defined( 'ABSPATH' ) || exit;

/**
 * @class Product
 */
class Product extends Product_Select_Rule_Abstract {

	/** @var string */
	public $data_item = 'product';


	/**
	 * Init the rule.
	 */
	public function init() {
		parent::init();

		$this->title         = __( 'Product - Product', 'automatewoo' );
		$this->compare_types = $this->get_is_or_not_compare_types();
	}


	/**
	 * @param \WC_Product|\WC_Product_Variation $product
	 * @param string                            $compare
	 * @param mixed                             $expected
	 * @return bool
	 */
	public function validate( $product, $compare, $expected ) {
		$expected_product = wc_get_product( absint( $expected ) );

		if ( ! $expected_product ) {
			return false;
		}

		$match = Logic_Helper::match_products( $product, $expected_product );

		switch ( $compare ) {
			case 'is':
				return $match;
			case 'is_not':
				return ! $match;
		}
	}
}
