import { instantiate } from "./lib/rs_lib.generated.js";
const { decode_qr } = await instantiate();

async function main() {
    if (Deno.args.length == 0) {
        console.error('No arguments assigned!');
        return;
    }
    
    console.log('Input files: ', Deno.args);
    for (let i = 0; i < Deno.args.length; i++) {
        let arg = Deno.args[i];
        console.log("----- Processing file: ", arg, '-----');
        try {
            let bytes = await Deno.readFile(arg);
            let qr_json = decode_qr(bytes);
            const parsed_qr = await JSON.parse(qr_json);
            console.log(JSON.stringify(parsed_qr, null, 4));
        } catch (e) {
            console.error('Process file: ', arg, ' failed: ', e + '');
        }
    }
}

await main();
