#!/usr/bin/env -S deno run --allow-read

import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts";

import { Dict, ExplorerGuesser, ManualProxy, Runner } from "./lib/lib.ts";
import { initialize_prompt } from "./lib/prompt.ts";
import { VerboseLogging } from "./lib/runner.ts";

import { francais } from "../data/data.ts";

async function main() {
	const args = await new Command().name("manual_proxy")
		.description(
			"Program to solve manually proxied TUSMO games with guesser controller.",
		)
		.option(
			"-f, --file <path:string>",
			"Sets dictionnary to use words from (defaults to internal french dict).",
		).parse(Deno.args);

	const init = initialize_prompt();

	let dict = Dict.from_lines(francais, init.length);
	if (args.options.file !== undefined) dict = await Dict.from_text_file(args.options.file, init.length);
	for (const [index, letter] of init.constraints) dict.constraint(index, letter);

	const guesser = new ExplorerGuesser(dict);
	const game = new ManualProxy(init.length);

	const runner = new Runner(game, guesser, new VerboseLogging());
	await runner.play_all();
}

if (import.meta.main) await main();
