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

use DSL::Examples;
use JSON::Fast;

my %*SUB-MAIN-OPTS = :named-anywhere;

#| Give DSL examples for specified language and workflow.
multi sub MAIN(
        Str:D $lang = 'Whatever',             #= Language.
        Str:D $workflow = 'Whatever',         #= Workflow.
        Str:D :from(:$from-lang) = 'English', #= Language to translate from.
        Str:D :f(:$format) = 'json',          #= Format of the result, one of "json" or "raku".
               ) {
    MAIN(:$lang, :$workflow, :$format, :$from-lang)
}

multi sub MAIN(
        Str:D :l(:to(:$lang)) = 'Whatever',    #= Language.
        Str:D :w(:$workflow) = 'Whatever',     #= Workflow.
        Str:D :from(:$from-lang) = 'English',  #= Language to translate from.
        Str:D :f(:$format) = 'json',           #= Format of the result, one of "json" or "raku".
               ) {
    my $langLocal = $lang.lc ∈ <whatever auto automatic> ?? Whatever !! $lang.tc;
    my $workflowLocal = $workflow.lc ∈ <whatever auto automatic> ?? Whatever !! $workflow;
    my $res = dsl-examples(lang => $langLocal, workflow => $workflowLocal, from => $from-lang);
    given $format.lc {
        when $_ eq 'json' { say to-json($res) }
        when $_ eq 'raku' { say $res.raku }
        default {
            note 'Unknown format.';
            say $res
        }
    }
}
