#pragma once

#include <stdbool.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "lvgl.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    AUDIO_IDLE = 0,
    AUDIO_CONNECTED,
    AUDIO_PLAYING,
    AUDIO_ERROR,
} audio_state_t;

/**
 * Initialize the audio streaming client.
 * @param uri  WebSocket URI (e.g. "ws://192.168.2.199:8766")
 * @param codec  Pointer to CodecPort instance (passed as void* for C linkage)
 */
void audio_client_init(const char *uri, void *codec);

/** Start the WebSocket connection and playback task. */
void audio_client_start(void);

/** Stop playback and disconnect. */
void audio_client_stop(void);

/** Get current audio client state. */
audio_state_t audio_client_get_state(void);

/**
 * Register a task to be notified (via xTaskNotifyGive) when a new status
 * image arrives.  Call before audio_client_start().
 */
void audio_client_set_image_notify_task(TaskHandle_t task);

/**
 * Get the latest status image descriptor.
 * @param updated  Set to true if a new image arrived since last call.
 * @return Pointer to the static image descriptor (always valid).
 */
const lv_img_dsc_t *audio_client_get_status_image(bool *updated);

/**
 * Acknowledge that the status image was successfully rendered.
 * Clears the updated flag so subsequent get_status_image calls return false.
 */
void audio_client_ack_status_image(void);

/**
 * Send any pending image request to the server.
 * Call from a task context (not from an event handler).
 * @return true if a request was sent, false if none pending or send failed.
 */
bool audio_client_send_pending_request(void);

#ifdef __cplusplus
}
#endif
