#include "reading_state.h"

#include <stdio.h>

static DailyReading s_reading;
static DailyInterpretation s_interp;

void reading_state_recompute(const BirthData *birth, Gender gender) {
  time_t now = time(NULL);
  /* Plain gmtime() (not the POSIX-only gmtime_r()), used immediately -
   * same justification as astro.c's own time_from_unix(). */
  struct tm *utc = gmtime(&now);

  char seed[16];
  snprintf(seed, sizeof seed, "%04d-%02d-%02d", utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday);

  reading_generate(seed, birth, gender, now, &s_reading);
  interpret_daily_reading(&s_reading, &s_interp);
}

const DailyReading *reading_state_get_reading(void) {
  return &s_reading;
}

const DailyInterpretation *reading_state_get_interpretation(void) {
  return &s_interp;
}
