#pragma once
// The REAPER-facing reads provenance needs, in one place. The pure provenance
// module (provenance.h) owns the fingerprint encoding, the recipe model, the
// FX-identity fold, and the parent-detection decision, all over plain
// strings/values; this shell gathers those strings/values from REAPER:
//   * the in-scope FX-chain identity of a source track (name/GUID/enabled rows),
//   * the media-file paths of a resolved capture's source items,
//   * the active book's bank samples resolved to absolute file paths,
//   * a canonical track-GUID string back to a live MediaTrack*.
//
// The .cpp includes reaper_plugin_functions.h WITHOUT REAPERAPI_IMPLEMENT
// (main.cpp owns the API pointers). MediaTrack is forward-declared so this header
// stays SDK-lite.

#include <optional>
#include <string>
#include <vector>

#include "core/model/provenance.h"

class MediaTrack;
class MediaItem;

namespace reasampler {

class BankBook;

using model::BankFileRef;

// The in-scope FX-chain identity of a source track (Track scope), folded to the
// pure provenance string via the track's own FX chain (TrackFX_*) in chain order.
std::string fxChainIdentityForTrack(MediaTrack* tr);

// The in-scope FX-chain identity for Item scope: enumerates each item's active
// take FX chain (TakeFX_*), in item order then FX order, combined with
// combineChainIdentities so distinct per-item partitions never collide. `items` is
// the same source-item set the shell collected for the item-scope capture.
std::string fxChainIdentityForItems(const std::vector<MediaItem*>& items);

// The media-file path of every selected media item's active take source,
// normalized to forward-slash. Unresolvable items (no take/source/name) are
// omitted — never an empty string in the result, so detectParent's "not in bank"
// branch is honest. This is the item-scope source set.
std::vector<std::string> selectedItemSourceFiles();

// The track-scope source set: media-file paths of the items on `tracks` that
// overlap the capture range [startSeconds, endSeconds). A track capture selects
// the track, not the item, so this is what "the source audio" means for it. Same
// normalize + omit-unresolvable contract as selectedItemSourceFiles; an item
// overlaps iff its [pos, pos+len) intersects the range with positive overlap (a
// zero-length touch does not count).
std::vector<std::string> trackItemSourceFiles(const std::vector<MediaTrack*>& tracks,
                                              double startSeconds, double endSeconds);

// Enumerates the active book's samples across every bank as pure BankFileRefs,
// each id paired with its file resolved to an absolute path against `projectDir`.
// An unresolvable path (empty projectDir/relativePath) gets an empty absolutePath,
// which detectParent never matches.
std::vector<BankFileRef> bankFileRefs(const BankBook& book, const std::string& projectDir);

// Resolves a canonical track-GUID string to a live MediaTrack* in the active
// project. Returns nullptr when no live track carries that GUID (the source track
// was deleted since capture — a re-capture failure mode the caller reports). The
// master track is not scanned (no membership GUID, never a capture source).
MediaTrack* trackByGuid(const std::string& guid);

}  // namespace reasampler
