#pragma once

#include <string>
#include <vector>

#include "core/audio_types.h"

namespace aptt {

struct BackendError {
  int code = 0;
  std::string message;
};

struct FormatProbeResult {
  FormatDescriptor requested;
  std::vector<FormatDescriptor> supported_formats;
  std::vector<std::string> rejection_reasons;
};

struct OperationResult {
  bool ok = false;
  BackendError error;

  static OperationResult Success() { return {true, {}}; }
  static OperationResult Failure(int code, std::string message) {
    return {false, {code, std::move(message)}};
  }
};

using DeviceList = std::vector<DeviceInfo>;

class IAudioBackend {
 public:
  virtual ~IAudioBackend() = default;

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

}  // namespace aptt

