#include "pair.h" /* pair */
#include "journal.h" /* size_t, date32, line64 */

/* Date-line to index in array map. */
#define TREE_NAME linemap
#define TREE_KEY union line64
#define TREE_VALUE size_t
#define TREE_HEAD
#include "../src/tree.h"

/* Source array. */
struct source { struct pair name, desc; };
#define ARRAY_NAME source
#define ARRAY_TYPE struct source
#define ARRAY_HEAD
#include "../src/array.h"

/* Place array. */
struct place { struct pair name; double x, y; };
#define ARRAY_NAME place
#define ARRAY_TYPE struct place
#define ARRAY_HEAD
#include "../src/array.h"

/* Score array. */
struct score {
	struct pair key, name;
	union date32 date, last/* update; need to compare leading value */;
	unsigned edges, score/* update */;
};
#define ARRAY_NAME score
#define ARRAY_TYPE struct score
#define ARRAY_HEAD
#include "../src/array.h"

/* Edit array. */
struct edit {
	union date32 edit;
	struct pair desc;
};
#define ARRAY_NAME edit
#define ARRAY_TYPE struct edit
#define ARRAY_HEAD
#include "../src/array.h"


/* Glider array. */
#define LAUNCH_TYPE \
	X(MotorCarTow),\
	X(Winch),\
	X(AeroTow)
#define X(type) type
enum launch_type { LAUNCH_TYPE };
#undef X
#define X(type) #type
static const char *launch_type_string[] = { LAUNCH_TYPE };
#undef X
#undef LAUNCH_TYPE
struct glider {
	struct pair type, reg, launch, landing;
	enum launch_type how;
	unsigned height_ft, pilot_min, dual_min, instr_min;
	struct pair remarks;
};
#define TREE_NAME glider
#define TREE_KEY union line64
#define TREE_VALUE struct glider
#define TREE_HEAD
#include "../src/tree.h"


/* Flight array. */
struct flight {
	struct pair type, reg, launch, landing, pilot, copilot;
	unsigned dual_min, pilot_min, ifrsim_min, ifr_min;
	struct pair remarks;
};
#define TREE_NAME flight
#define TREE_KEY union line64
#define TREE_VALUE struct flight
#define TREE_HEAD
#include "../src/tree.h"


#include "kjv.h"
#define TREE_NAME kjv
#define TREE_KEY union line64
#define TREE_VALUE struct kjvrange
#define TREE_HEAD
#include "../src/tree.h"


struct scan {
	struct {
		struct source_array array;
		struct pairmap_table map;
		struct linemap_tree dates;
	} sources, documents;
	struct {
		struct place_array array;
		struct pairmap_table map;
		struct linemap_tree dates;
	} places;
	struct {
		struct score_array array;
		struct pairmap_table map;
		struct linemap_tree dates;
	} scores;
	struct {
		struct edit_array array;
		struct pairmap_table map;
		struct linemap_tree dates;
	} edits;
	struct glider_tree gliders;
	struct flight_tree flights;
	struct kjv_tree kjvs;
};

void scan_(struct scan *);
struct scan scan(struct journal *);
const struct source *scan_source_lookup(struct scan *, const union line64);
void scan_score_graph(struct scan *);
void scan_glider_graph(struct scan *);
void scan_flight_graph(struct scan *);
void scan_kjv_graph(struct scan *);
