// ============================================================================
// test_face.c — closest-to-metal test harness for the universal operator.
// Hosted (uses stdio for output only); core/face_operator.c and the dialect
// under test remain freestanding-safe. Compiles and actually runs the real
// operator against the demo dialect: realize -> type input -> tick -> report.
// ============================================================================
#include <stdio.h>
#include "../core/face_node.h"

extern void face_bind_demo(struct FaceNode* f);

static void print_surface(const struct FaceNode* f)
{
  for(int r=0;r<f->rows;r++){
    for(int c=0;c<f->cols;c++) putchar(f->surface[r*f->cols+c]);
    putchar('\n');
  }
}

int main(void)
{
  struct FaceNode f = {0};
  face_bind_demo(&f);
  face_realize(&f);

  printf("== after realize() ==\n");
  print_surface(&f);
  printf("id=%llx genome=%s settle_lock=%d checkpoints=%u\n\n",
         (unsigned long long)f.id, f.genome, f.settle_lock, f.checkpoint_count);

  const char* typed = "HELLO UNIVERSAL FACE";
  for(const char* p = typed; *p; p++) face_key(&f, (uint8_t)*p);

  for(int i=0;i<5;i++) face_tick(&f);

  printf("== after face_key(\"%s\") + 5x face_tick() ==\n", typed);
  print_surface(&f);
  printf("genome=%s settle_lock=%d checkpoints=%u coord=%u\n",
         f.genome, f.settle_lock, f.checkpoint_count, f.basis.coord(f.self));

  // A second independent dialect instance must not share state with the
  // first (both are static-storage in their own dialect file) -- prove the
  // operator itself carries no cross-face state by re-realizing and
  // confirming a clean reset.
  face_realize(&f);
  printf("\n== after a second face_realize() (reset) ==\n");
  printf("settle_lock=%d checkpoints=%u (checkpoints reset to 0 by realize)\n",
         f.settle_lock, f.checkpoint_count);

  return 0;
}
