#ifndef EWSDR_DMR_H
#define EWSDR_DMR_H

#include <stddef.h>
#include <stdint.h>

#if defined(_WIN32)
#  if defined(EWSDR_DMR_BUILD)
#    define EWSDR_DMR_API __declspec(dllexport)
#  else
#    define EWSDR_DMR_API __declspec(dllimport)
#  endif
#else
#  define EWSDR_DMR_API __attribute__((visibility("default")))
#endif

#ifdef __cplusplus
extern "C" {
#endif

#define EWSDR_DMR_ABI_VERSION 1u
#define EWSDR_DMR_AMBE_BITS   96u
#define EWSDR_DMR_PCM_SAMPLES 160u

typedef struct ewsdr_dmr_mbe ewsdr_dmr_mbe;

typedef struct ewsdr_dmr_mbe_result {
  int errors_c0;
  int errors_total;
} ewsdr_dmr_mbe_result;

EWSDR_DMR_API uint32_t ewsdr_dmr_abi_version(void);
EWSDR_DMR_API ewsdr_dmr_mbe *ewsdr_dmr_mbe_create(int uv_quality);
EWSDR_DMR_API void ewsdr_dmr_mbe_destroy(ewsdr_dmr_mbe *decoder);
EWSDR_DMR_API void ewsdr_dmr_mbe_reset(ewsdr_dmr_mbe *decoder);

/*
 * Decode one already deinterleaved DMR AMBE+2 frame. ambe_bits is a row-major
 * char[4][24] matrix containing only 0/1 values. pcm_out receives 160 float
 * samples at 8 kHz. Frame extraction/deinterleaving remains in the DMR burst
 * layer, keeping mbelib and its state behind this stable ABI.
 */
EWSDR_DMR_API int ewsdr_dmr_mbe_decode(
    ewsdr_dmr_mbe *decoder,
    const uint8_t ambe_bits[EWSDR_DMR_AMBE_BITS],
    float pcm_out[EWSDR_DMR_PCM_SAMPLES],
    ewsdr_dmr_mbe_result *result);

#ifdef __cplusplus
}
#endif

#endif
