#pragma once

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

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

namespace aptt {

struct MmePcmPolicy {
  bool requires_explicit_device = true;
  bool keep_warm_after_signal = true;
  bool release_after_drain = false;
  bool uses_reset_on_normal_stop = false;
  bool reset_is_fault_only = true;
  std::uint32_t buffer_count = 4;
  std::uint32_t buffer_duration_ms = 20;
  std::uint32_t drain_timeout_ms = 2000;
  std::uint32_t release_cooldown_ms = 1000;
};

MmePcmPolicy MakeMmePcmPolicy(const PlaybackConfig& config);
bool IsMmePcmPlaybackFormat(const FormatDescriptor& format);

class MmePcmBackend final : public IAudioBackend {
 public:
  MmePcmBackend();
  ~MmePcmBackend() 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
