// SPDX-FileCopyrightText: 2025 Slatian
//
// SPDX-License-Identifier: LGPL-3.0-only

use crate::chain::CriteriumChainList;
use crate::CriteriumChain;

/// Allows turning iterators of `CriteriumChain`s directly into one `and` or `or` chain combining them with the given operator.
///
/// The fallback value for empty chains is `false`.
pub trait CollectAsChain<T> {
	/// Collect all items into an `and` chain.
	fn collect_as_and_chain(self) -> CriteriumChain<T>;
	/// Collect all items into an `or` chain.
	fn collect_as_or_chain(self) -> CriteriumChain<T>;
}

impl<T, I> CollectAsChain<T> for I
where
	I: Iterator<Item = CriteriumChain<T>>,
{
	fn collect_as_and_chain(self) -> CriteriumChain<T> {
		CriteriumChainList::from_iter(self).as_and()
	}

	fn collect_as_or_chain(self) -> CriteriumChain<T> {
		CriteriumChainList::from_iter(self).as_or()
	}
}
