using System.Threading.Tasks;
using TuneBoss.Core.Models;
namespace TuneBoss.Core.IO;
///
/// Serializes / parses the data section of a map file — the space- and
/// __-delimited table dump. Kept behind an interface because its exact
/// table ordering is interop-critical and is filled once the format (legacy-exact
/// vs. new) and the included save-types are confirmed.
///
/// Implementations live in the app layer, where they can read and write the
/// table view-models that hold the current ECU state.
///
public interface IMapTableCodec
{
///
/// Ensures any device-backed state required to serialize the given type is loaded,
/// re-reading tables whose models are not cached. Called before
/// so a save works even if the user reached this page before a full table load
/// finished (or a table read was missed). Default: nothing to do.
///
Task PrepareAsync(MapSaveType saveType, int cylinderCount) => Task.CompletedTask;
/// Runs an on-hardware diagnostic of the user-table read path and returns a report.
Task DiagnoseAsync() => Task.FromResult(string.Empty);
/// Serializes the current in-app table state into a map data section.
string Serialize(MapSaveType saveType, int cylinderCount);
///
/// Writes the currently-applied content for the given save type to the ECU,
/// optionally flashing at the end. Returns a human-readable summary.
///
Task WriteLoadedAsync(MapSaveType saveType, int cylinderCount, bool flash,
IProgress? progress = null)
=> throw new NotImplementedException("Write-to-ECU on load is not wired for this codec.");
/// Parses a map data section and applies it to the in-app table state.
void Deserialize(string data, MapSaveType saveType, int cylinderCount);
/// Rebuilds the editor nav trees from the current session layout
/// (used after an offline file establishes a layout, so entries exist to populate).
void RebuildNavTrees() { }
///
/// Builds an FSR document from the currently-loaded editors. Walks loaded entries
/// directly and skips anything not loaded (never throws "not loaded").
///
FsrFile.FsrDocument BuildFsrFromEditors(Models.EcuInfo? info, MapTag? tag, int cylinderCount);
/// Applies a parsed FSR document into the editors.
void ApplyFsr(FsrFile.FsrDocument doc);
}