<?php

namespace Repetito\Traits;

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

trait OrderUtils {

    protected function possibleFeeNames() {
        return array(
            'znovupouzitelny-obal-repetito',
            'znovupouzitelny-vratny-obal-repetito',
            'repetito-reusable-returnable-packaging',
        );
    }
    /**
     * Check if order has Repetito fee and return the fee item
     *
     * @param \WC_Order $order WooCommerce order object
     * @return \WC_Order_Item_Fee|false Fee item if found, false otherwise
     */
    protected function orderHasFee($order) {
        foreach ($order->get_items('fee') as $item_id => $item_fee) {
            if (in_array(sanitize_title($item_fee->get_name()), $this->possibleFeeNames())) {
                return $item_fee;
            }
        }
        return false;
    }

    protected function cartHasFee($cart) {
        foreach ($cart->get_fees() as $fee) {
            if (in_array(sanitize_title($fee->name), $this->possibleFeeNames())) {
                return true;
            }
        }
        return false;
    }
}

