package com.elphel.imagej.cuas.rt;

import java.awt.Rectangle;

/**
 * DNN inference backend for the CUAS L1+L2 pipeline. Implemented by {@link CuasDnnRemote} (TCP to the
 * Python infer_server, e.g. on the DGX) and {@link CuasDnnLocal} (in-process native LibTorch via JNA /
 * libtpdnn.so). CuasDetectRT.runDnnRemote() talks to this interface so the two are drop-in swappable;
 * the result type {@link CuasDnnRemote.BatchResult} is shared. By Claude on 06/27/2026.
 */
public interface CuasDnnBackend extends AutoCloseable {
	/** Upload the conditioned stack frames[T][H*W] (row-major) once; the backend builds the temporal
	 *  pyramid. Returns the per-level frame counts (and sets {@link #getNFrames()}). */
	int [] upload(float [][] frames, int H, int W) throws Exception;

	/** Temporal depth N of the loaded model (window length), known after {@link #upload}. */
	int getNFrames();

	/** Infer `count` scenes of a level in one call (newest_s = start + s*stride). rmaxCells>0 enables the
	 *  on-GPU ghostbuster. l2Enable/l2Reset drive Layer-2; noiseScale is the per-level L1-input scale. */
	CuasDnnRemote.BatchResult inferBatch(int level, int start, int count, int stride, Rectangle roi,
			double rmaxCells, boolean l2Enable, boolean l2Reset, double noiseScale) throws Exception;

	@Override
	void close();
}
