#pragma once

#include <Arduino.h>

struct BatchReassemblyState {
  bool active;
  uint16_t batch_id;
  uint8_t next_index;
  uint8_t expected_chunks;
  uint16_t total_len;
  uint16_t received_len;
  uint32_t last_rx_ms;
  uint32_t timeout_ms;
};

enum class BatchReassemblyStatus : uint8_t {
  InProgress = 0,
  Complete = 1,
  ErrorReset = 2
};

void batch_reassembly_reset(BatchReassemblyState &state);

BatchReassemblyStatus batch_reassembly_push(BatchReassemblyState &state, uint16_t batch_id, uint8_t chunk_index,
                                            uint8_t chunk_count, uint16_t total_len, const uint8_t *chunk_data,
                                            size_t chunk_len, uint32_t now_ms, uint32_t timeout_ms_for_new_batch,
                                            uint16_t max_total_len, uint8_t *buffer, size_t buffer_cap,
                                            uint16_t &out_complete_len);
