#include "tarot.h"
#include "rng.h"

void tarot_draw_celtic_cross(const char *seed, CelticCrossSpread *out) {
  TarotCard deck[TAROT_DECK_SIZE];
  for (int i = 0; i < TAROT_DECK_SIZE; i++) {
    deck[i] = (TarotCard)i;
  }

  RngState rng;
  rng_init(&rng, rng_seed_from_string(seed));

  /* Partial Fisher-Yates: only shuffle the prefix we actually need, one
   * slot at a time, drawing the reversal bit for a card immediately
   * after it's picked. Same distribution as a full shuffle, and the
   * draw order this produces is exactly reproducible from the seed. */
  for (int i = 0; i < TAROT_SPREAD_SIZE; i++) {
    int j = i + (int)rng_next_bounded(&rng, (uint32_t)(TAROT_DECK_SIZE - i));
    TarotCard tmp = deck[i];
    deck[i] = deck[j];
    deck[j] = tmp;

    out->positions[i].card = deck[i];
    out->positions[i].reversed = rng_next_bounded(&rng, 2) != 0;
  }
}
