// Prueba de mano: autocomplete archivo_de_terminos prefijo k
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>

#include "autocomplete.h"

int main(int argc, char** argv) {
    if (argc != 4) {
        std::cerr << "uso: autocomplete archivo_de_terminos prefijo k\n";
        return 2;
    }
    std::vector<Term> terms;
    if (!load_terms(argv[1], terms)) {
        std::cerr << "no se pudo leer " << argv[1] << "\n";
        return 1;
    }
    sort_by_text(terms);
    Range range = prefix_range(terms, argv[2]);
    std::printf("%zu términos empiezan con \"%s\"\n", range.last - range.first, argv[2]);
    for (const Term& term : top_k(terms, range, static_cast<std::size_t>(std::atol(argv[3])))) {
        std::printf("%7lld  %s\n", term.weight, term.text.c_str());
    }
    return 0;
}
