#pragma once

#include <filesystem>
#include <optional>
#include <string>
#include <vector>

#include "core/audio_backend.h"
#include "core/device_discovery.h"
#include "core/diagnostic_log.h"
#include "core/pcm_diagnostics.h"

namespace aptt {

inline constexpr int kDiagnosticBundleSchemaVersion = 1;

struct DiagnosticBuildMetadata {
  int schema_version = kDiagnosticBundleSchemaVersion;
  std::string app_name;
  std::string app_version;
  std::string build_type;
  std::string compiler;
  std::string compiler_version;
  std::string cxx_standard;
  std::string target_arch;
  bool enable_asio = false;
};

struct DiagnosticBundleInput {
  std::string session_id;
  std::string created_utc;
  PlaybackConfig config;
  DeviceInfo device;
  FormatProbeResult format_probe;
  std::optional<DiscoverySnapshot> discovery_snapshot;
  std::vector<DiagnosticEvent> events;
  RealtimeStats final_stats;
  bool release_attempted = false;
  bool release_ok = false;
  std::string release_backend = "none";
  std::string release_status = "not-attempted";
  std::string release_error;
  RealtimeStats release_stats;
  PcmRunSummary pcm_summary;
  DiagnosticBuildMetadata build_metadata;
  std::optional<std::string> diagnostic_plan_json;
  std::optional<std::string> diagnostic_score_json;
  std::optional<std::string> selected_condition_json;
  std::vector<std::string> ui_log_lines;
  std::string summary;
  bool allow_overwrite = false;
};

DiagnosticBuildMetadata MakeCurrentDiagnosticBuildMetadata();

OperationResult WriteDiagnosticBundleDirectory(
    const std::filesystem::path& output_directory,
    const DiagnosticBundleInput& input);

OperationResult WriteDiagnosticBundleZip(
    const std::filesystem::path& zip_path,
    const DiagnosticBundleInput& input);

}  // namespace aptt
