use askama::Template;

use crate::{
	RuntimeModule,
	common::{Game, GameProps, drops::Drops, enemy::Enemy, synthesis::Synthesis},
	create_file,
};

const ENEMIES_PATH: &str = "./input/kh1fm/enemies";
const SYNTHESIS_PATH: &str = "./input/kh1fm/synthesis.toml";

#[derive(Template)]
#[template(path = "pages/kh1/drops.html")]
struct DropsTemplate {
	pub data: Drops,
}

#[derive(Template)]
#[template(path = "pages/kh1/synth.html")]
struct SynthTemplate {
	pub data: Synthesis,
}

pub struct Module;

impl RuntimeModule for Module {
	fn start_module() {
		tracing::info!("Loading KH1FM enemy data from {}", ENEMIES_PATH);
		let enemies = Enemy::import(ENEMIES_PATH);

		let drops = Drops::new(Game::Kh1(GameProps::final_mix()), enemies);

		tracing::info!("Loading KH1FM synthesis data from {}", SYNTHESIS_PATH);
		let synth = Synthesis::new(SYNTHESIS_PATH);

		tracing::info!("Generating KH1FM drops template");
		let drops_template = DropsTemplate { data: drops };

		create_file("./out/kh1fm", "drops", drops_template).unwrap();

		tracing::info!("Generating KH1FM synth template");
		let synth_template = SynthTemplate { data: synth };

		create_file("./out/kh1fm", "synth", synth_template).unwrap();
	}
}
