#!/usr/bin/env perl6

use v6;
use Questhub;
use Term::ANSIColor;

sub MAIN('list', :$owner?, :$status?, :$tags?) {
    my $qh = Questhub.new;
    my @quests = $qh.get_quests(:user($owner), :$status);
    for @quests -> $q {
        if $tags {
            my @tags = grep { $_ }, $tags.split: /<before <[+-]> >/;
            my %c = classify { my $x = .substr(0,1); substr-rw($_,0,1) = ''; $x }, @tags;
            next unless any(@($q.tags)) ~~ any(@(%c<+>)) & none(@(%c<->));
        }
        my $tags-str = join ", ", map { colored($_, 'magenta') }, $q.tags;
        say join " ", colored($q.id, 'yellow'), colored(~+$q.likes, 'red'), colored($q.status, "blue"), $tags-str, $q.name;
    }
}
