#pragma once

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

#include "core/audio_types.h"
#include "core/diagnostic_log.h"

namespace aptt {

struct PcmMetricAvailability {
  bool queue_depth = false;
  bool padding_frames = false;
  bool play_write_cursor = false;
  bool lock_unlock_timing = false;
  bool lost_buffer_events = false;
  bool device_invalidation = false;
};

struct PcmRunSummary {
  int schema_version = 1;
  BackendApi backend = BackendApi::kNull;
  std::string device_id;
  std::optional<DeviceLifecycleState> final_lifecycle_state;
  RealtimeStats common_counters;
  PcmMetricAvailability metrics;
  std::vector<std::string> unsupported_metrics;
  std::map<std::string, std::string> backend_fields;
  bool auto_retry_attempted = false;
  bool auto_backend_switch_attempted = false;
};

PcmMetricAvailability PcmMetricAvailabilityForBackend(BackendApi backend);
PcmRunSummary BuildPcmRunSummary(BackendApi backend,
                                std::string device_id,
                                const std::vector<DiagnosticEvent>& events,
                                const RealtimeStats& final_stats);
std::string SerializePcmRunSummaryJson(const PcmRunSummary& summary);
std::string SerializePcmComparisonCsv(
    const std::vector<PcmRunSummary>& summaries);

}  // namespace aptt
