#!/usr/bin/perl -w
#
#  rhrdlibs
#
#  Copyright (C) 2015-2016 Christian Pointner <equinox@helsinki.at>
#
#  This file is part of rhrdlibs.
#
#  rhrdlibs is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Affero General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  any later version.
#
#  rhrdlibs is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Affero General Public License for more details.
#
#  You should have received a copy of the GNU Affero General Public License
#  along with rhrdlibs. If not, see <http://www.gnu.org/licenses/>.
#

use strict;
use POSIX;
use lib "../lib/";
use RHRD::rddb;


my $username = $ARGV[0];
$username = undef if (defined($username) && $username eq '');
my $groupname = $ARGV[1];
$groupname = undef if (defined($groupname) && $groupname eq '');
my $type = $ARGV[2];


my @dropboxes = ();
my ($ctx, $status, $errorstring) = RHRD::rddb::init();
if(defined $ctx) {
  @dropboxes = RHRD::rddb::get_dropboxes($ctx, $username, $groupname, $type);
  if(!defined $dropboxes[0] && defined $dropboxes[1]) {
    print STDERR "$dropboxes[1]: $dropboxes[2]";
    RHRD::rddb::destroy($ctx);
    exit 1;
  }
  RHRD::rddb::destroy($ctx);
} else {
  print STDERR "$errorstring\n";
  exit 1;
}


print "Dropboxes:\n";
for my $href (@dropboxes) {
  print " *  group:" . $href->{'GROUP'} . "\n";
  print "    group-description:" . $href->{'GROUPDESC'} . "\n";
  print "    group-low-cart:" . $href->{'GROUPLOWCART'} . "\n";
  print "    group-high-cart:" . $href->{'GROUPHIGHCART'} . "\n";
  print "    normalization-level:" . floor($href->{'NORMLEVEL'}/100) . "\n";
  print "    autotrim-level:" . floor($href->{'TRIMLEVEL'}/100) . "\n";
  print "    parameters:" . $href->{'PARAM'} . "\n";
  print "    type:" . $href->{'TYPE'} . "\n";
  if($href->{'TYPE'} eq "show") {
    print "    show-id:" . $href->{'SHOWID'} . "\n";
    print "    show-title:" . $href->{'SHOWTITLE'} . "\n";
    print "    show-log:" . $href->{'SHOWLOG'} . "\n";
    print "    show-rhythm:" . $href->{'SHOWRHYTHM'} . "\n";
    print "    show-dayofweek:" . $href->{'SHOWDOW'} . "\n";
    print "    show-starttime:" . $href->{'SHOWSTARTTIME'} . "\n";
    print "    show-length:" . $href->{'SHOWLEN'} . "\n";
  } elsif($href->{'TYPE'} eq "jingle") {
    print "    jingle-title:" . $href->{'JINGLETITLE'} . "\n";
  } elsif($href->{'TYPE'} eq "musicpool") {
    print "    musicpool-title:" . $href->{'MUSICPOOLTITLE'} . "\n";
    print "    musicpool-clock:" . $href->{'MUSICPOOLCLOCK'} . "\n";
  }
  print "\n";
}