use needletail::Sequence;
use pyo3::prelude::*;
use pyo3_stub_gen::derive::*;

/// Normalize a DNA sequence by converting any non-standard nucleotides to standard ones.
///
/// This function takes a DNA sequence as a `String` and a boolean flag `iupac` indicating whether to normalize using IUPAC ambiguity codes.
/// It returns a normalized DNA sequence as a `String`.
///
/// # Arguments
///
/// * `seq` - A DNA sequence as a `String`.
/// * `iupac` - A boolean flag indicating whether to normalize using IUPAC ambiguity codes.
///
/// # Returns
///
/// A normalized DNA sequence as a `String`.
#[gen_stub_pyfunction(module = "deepbiop.core")]
#[pyfunction]
pub fn normalize_seq(seq: String, iupac: bool) -> String {
    String::from_utf8_lossy(&seq.as_bytes().normalize(iupac)).to_string()
}

/// Generate the reverse complement of a DNA sequence.
///
/// This function takes a DNA sequence as a `String` and returns its reverse complement.
/// The reverse complement is generated by reversing the sequence and replacing each nucleotide
/// with its complement (A<->T, C<->G).
///
/// # Arguments
///
/// * `seq` - A DNA sequence as a `String`
///
/// # Returns
///
/// The reverse complement sequence as a `String`
///
/// # Example
///
/// ```
/// use deepbiop_core::seq::reverse_complement;
///
/// let seq = String::from("ATCG");
/// let rev_comp = reverse_complement(seq);
/// assert_eq!(rev_comp, "CGAT");
/// ```
#[gen_stub_pyfunction(module = "deepbiop.core")]
#[pyfunction]
pub fn reverse_complement(seq: String) -> String {
    String::from_utf8(seq.as_bytes().reverse_complement()).unwrap()
}
