#include "ConflictSet.h"

#include <cassert>
#include <cstdio>

using namespace weaselab;

int main(void) {
  ConflictSet cs(0);
  ConflictSet::WriteRange w;
  w.begin.p = (const uint8_t *)"0000";
  w.begin.len = 4;
  w.end.len = 0;
  cs.addWrites(&w, 1, 1);
  ConflictSet::Result result;
  ConflictSet::ReadRange r;
  r.begin.p = (const uint8_t *)"0000";
  r.begin.len = 4;
  r.end.len = 0;
  r.readVersion = 0;
  cs.check(&r, &result, 1);
  assert(result == ConflictSet::Conflict);
  int64_t bytes = cs.getBytes();
  assert(bytes > 0);

  ConflictSet::MetricsV1 *metrics;
  int metricsCount;
  cs.getMetricsV1(&metrics, &metricsCount);
  for (int i = 0; i < metricsCount; ++i) {
    printf("# HELP %s %s\n", metrics[i].name, metrics[i].help);
    printf("# TYPE %s %s\n", metrics[i].name,
           metrics[i].type == metrics[i].Counter ? "counter" : "gauge");
    printf("%s %g\n", metrics[i].name, metrics[i].getValue());
  }
}
