#!/usr/bin/perl

=encoding UTF-8
=cut

=head1 DESCRIPTION

=cut

# project modules
use lib::abs qw(
    ../lib
);
use qbit;
use Application;

# common modules
use feature 'say';
use Carp;
use DDP;

# global vars

# subs

# main
sub main {
    my $app = Application->new();
    $app->pre_run();

    my $type2fields = {};

    foreach my $field (@Application::Model::BKStatistics::FIELDS) {
        foreach my $type (qw(select where group_by)) {
            if ($field->{$type}) {
                push(@{$type2fields->{$type}}, $field);
            }
        }
    }

    foreach my $type (qw(select)) {
        say "## $type";
        my $i = 1;
        foreach my $field (sort {$a->{frontend_type} cmp $b->{frontend_type}} @{$type2fields->{$type}}) {
            print sprintf "%2s %30s - %-30s %-30s\n",
                $i,
                $field->{partner2_id},
                $field->{frontend_type},
                $field->{frontend_unit},
                ;
            $i++;
        }
        say '';
    }

    foreach my $type (qw(where group_by)) {
        say "## $type";
        my $i = 1;
        foreach my $field (sort {$a->{frontend_type} cmp $b->{frontend_type}} @{$type2fields->{$type}}) {
            print sprintf "%2s %30s - %-30s\n",
                $i,
                $field->{partner2_id},
                $field->{frontend_type},
                ;
            $i++;
        }
        say '';
    }

    $app->post_run();
}
main();
__END__
