// Stub JNIEnv: valide libkazeia_engine.so generate() sur device, sans Java.
#include <cstdio>
#include <cstring>
#include <dlfcn.h>
struct Str { const char* s; };
static const char* getUTF(void*, Str* j, void*){ return j->s; }
static void relUTF(void*, Str*, const char*){}
static Str* newUTF(void*, const char* s){ static Str r; r.s=s; return &r; }
// table indices: 169=NewStringUTF,167=GetStringUTFChars,168=Release (suffisant ici)
int main(int c, char** v){
  void* p[300]={0}; p[169]=(void*)newUTF; p[167]=(void*)getUTF; p[168]=(void*)relUTF;
  void** env=p; void* h=dlopen("libkazeia_engine.so",RTLD_NOW);
  if(!h){printf("dlopen fail: %s\n",dlerror());return 1;}
  auto load=(long(*)(void**,void*,Str*,int))dlsym(h,"Java_com_kazeia_llm_EngineJni_load");
  auto gen=(Str*(*)(void**,void*,long,Str*,int))dlsym(h,"Java_com_kazeia_llm_EngineJni_generate");
  Str mp{v[1]}, pr{"Kazeia psy. Patient: je vais mal. Une phrase:"};
  long k=load(env,0,&mp,2048); printf("h=%ld\n",k); if(!k)return 2;
  Str* r=gen(env,0,k,&pr,20); printf("OUT:[%s]\n",r->s); return 0;
}
