#ifndef HUSH_IMAGE_CACHE_H
#define HUSH_IMAGE_CACHE_H
#include <SDL.h>
#include <stdbool.h>

/* Pure path resolution -- no SDL/file-I/O, unit-testable. Absolute imageRef (leading '/') passes
   through unchanged; a relative imageRef is joined against the directory of docFilePath. Returns
   false (nothing written to outBuf) if imageRef is NULL/empty, or if imageRef is relative and
   docFilePath is NULL (an unsaved buffer has no directory to resolve against) or the result
   wouldn't fit in outBuf. */
bool image_resolve_path(const char *docFilePath, const char *imageRef, char *outBuf, int outBufSize);

typedef struct ImageCache ImageCache; /* opaque; growable array of cached entries */
void image_cache_init(ImageCache **cache);
void image_cache_free(ImageCache *cache);

/* Looks up (lazily loading and caching on first sight, keyed by resolvedPath) the texture for an
   already-resolved absolute path. Every call -- hit or miss -- cheaply re-stat()s the file and
   compares mtime/existence against the cached entry, reloading or re-failing as needed, so an
   image edited/created on disk while hush is open is picked up on the next lookup rather than
   being stuck permanently broken or permanently stale. Returns false (outTexture/outW/outH
   untouched) if the file can't be resolved/loaded. Never called by hush_test -- needs a live
   SDL_Renderer and a real window/video subsystem, neither of which the headless test binary has. */
bool image_cache_get(ImageCache *cache, SDL_Renderer *renderer, const char *resolvedPath,
                      SDL_Texture **outTexture, int *outW, int *outH);

#endif
