use std::sync::Arc;
use mux_circuits::sub::full_subtractor;
use parasol_concurrency::AtomicRefCell;
use crate::{Encryption, FheCircuit, L1GlweCiphertext};
pub mod add;
pub mod mul;
pub mod sub;
pub fn sub_circuit(
width: usize,
c1: &[Arc<AtomicRefCell<L1GlweCiphertext>>],
c2: &[Arc<AtomicRefCell<L1GlweCiphertext>>],
c_borrow: Option<&[Arc<AtomicRefCell<L1GlweCiphertext>>]>,
enc: &Encryption,
) -> (FheCircuit, Vec<Arc<AtomicRefCell<L1GlweCiphertext>>>) {
let mut graph = FheCircuit::new();
let sub_circuit = full_subtractor(width, c_borrow.is_some());
let inputs = c_borrow
.unwrap_or(&[])
.iter()
.chain(c1.iter().zip(c2.iter()).flat_map(|(a, b)| [a, b]))
.cloned()
.collect::<Vec<_>>();
let outputs = graph.insert_mux_circuit_and_connect_inputs(&sub_circuit, &inputs, enc);
(graph, outputs)
}