#pragma once

#include <cstdint>
#include <memory>
#include <vector>

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

namespace aptt {

struct WasapiSharedPcmPolicy {
  bool requires_explicit_endpoint = true;
  bool keep_warm_after_signal = true;
  bool release_after_drain = false;
  bool uses_reset_on_normal_stop = false;
  bool uses_fallback_endpoint = false;
  bool uses_fallback_format = false;
  std::uint32_t buffer_duration_ms = 100;
  std::uint32_t render_poll_interval_ms = 5;
  std::uint32_t release_cooldown_ms = 1000;
};

WasapiSharedPcmPolicy MakeWasapiSharedPcmPolicy(const PlaybackConfig& config);
bool IsWasapiSharedPcmPlaybackFormat(const FormatDescriptor& format);

class WasapiSharedPcmBackend final : public IAudioBackend {
 public:
  WasapiSharedPcmBackend();
  ~WasapiSharedPcmBackend() override;

  BackendApi api() const override;
  DeviceList enumerateDevices() override;
  FormatProbeResult probeFormats(const DeviceInfo& device) override;
  OperationResult initialize(const PlaybackConfig& config) override;
  OperationResult start() override;
  OperationResult stop() override;
  OperationResult reset() override;
  RealtimeStats getRealtimeStats() const override;
  BackendError getLastError() const override;
  OperationResult shutdown() override;

  DeviceLifecycleState lifecycle_state() const;
  std::vector<DiagnosticEvent> diagnostic_events() const;

 private:
  struct Impl;
  std::unique_ptr<Impl> impl_;
};

}  // namespace aptt
