#pragma once
// Single-capture orchestration + the realtime/insert action bodies: renderOffline
// (one offline render under the scope's FxBypassGuard, shared by single-shot/
// batch/recapture), captureAndIndexOne (render + provenance + bank add +
// tracking-ledger record, unpersisted), RunCapture/RunCaptureItemAssign,
// RunCaptureRealtimeTrack/RunCancelRealtime (in-flight state lives in
// realtime_lifecycle), and RunInsertSelected — the one deliberate exception to
// capture-never-places.
//
// The session is threaded explicitly; no capture path here calls InsertMedia
// or touches the timeline except RunInsertSelected, on purpose, via the insert shell.
//
// The .cpp includes reaper_plugin_functions.h WITHOUT REAPERAPI_IMPLEMENT
// (main.cpp owns the API pointers).

#include <string>

#include "shell/capture/capture.h"        // CaptureResult / CaptureRequest
#include "shell/capture/scope_resolve.h"  // ResolvedSource
#include "core/capture/render_settings.h" // CaptureScope, CaptureActionDef

namespace reasampler {
class ReaSamplerSession;
}

namespace reasampler::capture {

// Renders one CaptureRequest through the offline backend under the scope's
// FX-bypass guard. Shared by RunCapture and RunRecaptureFromSource so the
// FX-scope neutralize + render recipe lives in one place. Non-destructive;
// writes a file only.
CaptureResult renderOffline(CaptureScope scope,
                            const std::vector<MediaTrack*>& sourceTracks,
                            const CaptureRequest& req);

// Renders one capture request, stamps provenance, adds the Sample to the
// active bank + tracking ledger — without persisting (batch persists once
// at the end). res.sample.id carries the landed bank-index id (fresh add or
// hash-dedup collapse target).
CaptureResult captureAndIndexOne(ReaSamplerSession& session,
                                 CaptureScope scope,
                                 const ResolvedSource& src,
                                 const CaptureName& name,
                                 double startSeconds,
                                 double endSeconds);

// Runs one capture-action-table row: resolve, render + add + record, persist +
// mark dirty. Returns the landed bank-index id ("" on failure/no-op) — the
// arrange-ingest capture+assign path consumes it; plain capture actions ignore it.
std::string RunCapture(ReaSamplerSession& session, const CaptureActionDef& def);

// Item-scope capture into the active bank + assignment-request write, in one
// undo block.
void RunCaptureItemAssign(ReaSamplerSession& session);

// Starts the realtime track capture (async, timer-driven — in-flight state is
// realtime_lifecycle's) / cancels the in-flight one.
void RunCaptureRealtimeTrack(ReaSamplerSession& session);
void RunCancelRealtime(ReaSamplerSession& session);

// Places the bank panel's selected sample(s) at the edit cursor via the
// insert shell. `conform` selects the explicit opt-in tempo-match variant.
void RunInsertSelected(ReaSamplerSession& session, bool conform);

}  // namespace reasampler::capture
