#ifndef TIMER_H
#define TIMER_H

#include <stdint.h>
#include <SDL3/SDL.h>

typedef Uint32 (*TimerCallback)(Uint32 timer_id, Uint32 interval, void *param);

typedef struct {
  Uint32         id;
  uint64_t       due_ns;
  uint64_t       interval_ns;
  TimerCallback  callback;
  void          *param;
} cell_timer_t;

/* Initialize timer system - must be called once */
void timer_init(void);

/* Shutdown timer system - must be called before exit */
void timer_quit(void);

/* Schedule a new timer to fire after delay_ns nanoseconds */
Uint32 add_timer_ns(uint64_t delay_ns, TimerCallback callback, void *param);

/* Cancel a pending timer by its ID */
void remove_timer(Uint32 id);

/* Process due timers - call once per main loop iteration */
void process_due_timers(void);

/* Get time until next timer expires (in nanoseconds) */
uint64_t next_timeout_ns(void);

/* Get current monotonic time in nanoseconds */
uint64_t get_time_ns(void);

#endif /* TIMER_H */