/*******************************************************************************
 *
 *    Copyright (c) 2025 - 2026 Haixing Hu.
 *
 *    SPDX-License-Identifier: Apache-2.0
 *
 *    Licensed under the Apache License, Version 2.0.
 *
 ******************************************************************************/
// qubit-style: allow explicit-imports
//! Defines the `RcConditionalBiFunction` public type.

#![allow(unused_imports)]

use super::*;

// ============================================================================
// RcConditionalBiFunction - Rc-based Conditional BiFunction
// ============================================================================

/// RcConditionalBiFunction struct
///
/// A single-threaded conditional bi-function that only executes when a
/// bi-predicate is satisfied. Uses `RcBiFunction` and `RcBiPredicate` for
/// shared ownership within a single thread.
///
/// This type is typically created by calling `RcBiFunction::when()` and is
/// designed to work with the `or_else()` method to create if-then-else logic.
///
/// # Features
///
/// - **Shared Ownership**: Cloneable via `Rc`, multiple owners allowed
/// - **Single-Threaded**: Not thread-safe, cannot be sent across threads
/// - **Conditional Execution**: Only computes when bi-predicate returns `true`
/// - **No Lock Overhead**: More efficient than `ArcConditionalBiFunction`
///
/// # Examples
///
/// ```rust
/// use qubit_function::{BiFunction, RcBiFunction};
///
/// let add = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
/// let multiply = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
/// let conditional = add.when(|x: &i32, y: &i32| *x > 0).or_else(multiply);
///
/// let conditional_clone = conditional.clone();
///
/// assert_eq!(conditional.apply(&5, &3), 8);
/// assert_eq!(conditional_clone.apply(&-5, &3), -15);
/// ```
///
pub struct RcConditionalBiFunction<T, U, R> {
    pub(super) function: RcBiFunction<T, U, R>,
    pub(super) predicate: RcBiPredicate<T, U>,
}

// Implement RcConditionalBiFunction
impl_shared_conditional_function!(
    RcConditionalBiFunction<T, U, R>,
    RcBiFunction,
    BiFunction,
    into_rc,
    'static
);

// Use macro to generate Debug and Display implementations
impl_conditional_function_debug_display!(RcConditionalBiFunction<T, U, R>);

// Implement Clone for RcConditionalBiFunction
impl_conditional_function_clone!(RcConditionalBiFunction<T, U, R>);
