#!/usr/bin/perl -w
#

use strict;

use Getopt::Std;
use File::Basename;

use lib '/app/tools/metadata/lib';
use Metadata::Dumper::App;

my %opt;
usage() unless getopts( 'a:c:wqhldv', \%opt );

if ( $opt{l} ) {
    list_clients( $ARGV[0] );
}

if ( $opt{h} ) {
    usage();
}

my $dumper = new Metadata::Dumper::App(
    client_id => $opt{c},
    raw       => $opt{w},
    album_id  => $opt{a},
    quiet     => $opt{q},
    verbose   => $opt{v},
    debug     => $opt{d}
);

$dumper->run();

sub usage {
    my $prog = basename $0;

    print <<EofUSAGE;

usage: $prog [-c client_id] [-r report_email_address] [-x error_email_address] [-l client_name/pattern] [-h] [-d]
            -c - Client ID (if not specified then run for all clients)
            -a - Album ID (if not specified then get all albums)
            -l - List client ids (host pattern is optional)
            -w - Dump raw untranslated XML
            -d - display debug information to STDERR
            -v - display verbose debug information to STDERR
            -q - Do not output summary report
            -h - display this screen
EofUSAGE

    exit 1;
}

sub list_clients {
    my $host = shift;
    my $key;
    foreach $key ( sort { $a <=> $b } keys(%Common::RSDB::CLIENT_DB) ) {
        printf( "%-20s %-10s ID: %s\n", $Common::RSDB::CLIENT_DB{$key}->{db_name}, "($Common::RSDB::CLIENT_DB{$key}->{host_id})", $key )
          if ( !defined($host) || $Common::RSDB::CLIENT_DB{$key}->{db_name} =~ /$host/i );
    }
    exit 1;
}
