#pragma once

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "Tick.h"

struct Command;

struct ReplayHeader
{
    int          version = 0;
    std::string  build;
    unsigned int seed = 0;
    std::string  configHash;
    std::string  timestamp;
};

// One entry of the replay stream: either a command (applied at its tick) or an
// RNG checksum (verified at its tick). Entries are kept in file order, which is
// the canonical order the playback driver reproduces.
struct ReplayEntry
{
    Tick                           tick        = 0;
    bool                           isCommand   = false;
    std::shared_ptr<const Command> command;        // set iff isCommand
    std::uint64_t                  fingerprint = 0; // set iff !isCommand
};

struct ParsedReplay
{
    ReplayHeader             header;
    std::vector<ReplayEntry> entries;
};

// Parses a replay file (header + command/checksum stream). Returns nullopt on an
// I/O failure or malformed content (e.g. an unparseable command line).
std::optional<ParsedReplay> readReplayFile(const std::string& path);
