#!/usr/bin/env raku
use v6.d;

use Lingua::NumericWordForms;

multi format-output(Str $format, $output) {
    given $format.lc {
        when $_ eq 'raku' && $output.elems == 1 { say $output[0].raku; }
        when $output.elems == 1 { say $output[0]; }
        when $_ (elem) <string text> { say $output.join('; '); }
        when $_ (elem) <lines> { .say for $output.List; }
        default { say $output.raku; }
    }
}

#| Coverts numbers into numeric word forms.
multi sub MAIN(Str $text,                          #= String of one or more numbers to convert into numeric word forms. (Multiple numbers can be separated with ';'.)
               Str :l(:$lang) = 'English',         #= Language (one of 'English' or 'Koremutake'.)
               Str :f(:$format) = 'text'           #= Output format one of 'text', 'lines', or 'raku'.
               ) {
    my @res = to-numeric-word-form($text, $lang);
    format-output($format, @res);
}

#| Takes a list of numbers and converts it into a list of numeric word forms.
multi sub MAIN(*@words,                            #= Number strings to be converted into numeric word forms.
               Str :l(:$lang) = 'English',         #= Language (one of 'English' or 'Koremutake'.)
               Str :f(:$format) = 'text'           #= Output format one of 'text', 'lines', or 'raku'.
               ) {
    my @res = to-numeric-word-form( @words.join(';'), $lang);
    format-output($format, @res);
}

#| Converts numbers from a (pipeline) input into numeric word forms.
multi sub MAIN(Str :l(:$lang) = 'English',         #= Language (one of 'English' or 'Koremutake'.)
               Str :f(:$format) = 'text'           #= Output format one of 'text', 'lines', or 'raku'.
               ) {
    my $text = lines>>.trim.join(';');
    format-output($format, to-numeric-word-form($text, $lang));
}