///|
/// Bio.Restriction demo: a REBASE-style restriction map of a small linear
/// construct and a circular mini-plasmid.
///
/// Showcases: the 1088-enzyme database, batch search / RestrictionAnalysis
/// filters, single and double digest fragment tables (linear and circular),
/// overhang classification, compatible ends and isoschizomer relationships.
///
/// Run with: moon run examples/restriction_demo
fn fmt_cuts(cuts : Array[Int32]) -> String {
  if cuts.length() == 0 {
    "-"
  } else {
    let mut s = ""
    for i in 0.. 0 {
        s += ", "
      }
      s += cuts[i].to_string()
    }
    s
  }
}

///|
fn fmt_names(enzymes : Array[@bio.BioRestrictionEnzyme]) -> String {
  if enzymes.length() == 0 {
    "-"
  } else {
    let mut s = ""
    for i in 0.. 0 {
        s += ", "
      }
      s += enzymes[i].name
    }
    s
  }
}

///|
fn fmt_strs(xs : Array[String]) -> String {
  if xs.length() == 0 {
    "-"
  } else {
    let mut s = ""
    for i in 0.. 0 {
        s += ", "
      }
      s += xs[i]
    }
    s
  }
}

///|
/// Fragment lengths of a digest from sorted cut positions.
fn digest_lengths(
  cuts : Array[Int32],
  length : Int32,
  linear : Bool,
) -> Array[Int32] {
  let c = cuts.copy()
  c.sort()
  let r : Array[Int32] = []
  if c.length() == 0 {
    r.push(length)
    return r
  }
  if linear {
    let mut prev = 0
    for pos in c {
      r.push(pos - prev)
      prev = pos
    }
    r.push(length - prev)
  } else {
    for i in 1..
        if cuts.length() > 0 {
          if window_names != "" {
            window_names += ", "
          }
          window_names += name + " [" + fmt_cuts(cuts) + "]"
        }
      None => ()
    }
  }
  println("enzymes cutting in region 20..40: " + window_names)
  println(
    "enzymes that do not cut anywhere: " +
    analysis.do_not_cut(1, construct.length() + 1).length().to_string(),
  )
  println("")

  // ------------------------------------------------------------------
  // 7. Supplier catalogue
  // ------------------------------------------------------------------
  println("== supplier catalogue ==")
  println(
    "enzymes sold by supplier code 'N' (e.g. NEB): " +
    @bio.bio_restriction_enzymes_by_supplier("N").length().to_string(),
  )
}