use Data::Dumper;
use StagedStaticData;

print("album tracks\n");
my $at = StagedStaticData::AlbumTrackTable->new();
$at->loadDataFile("album_track");

print "num items: " . $at->numItems() . "\n";

while (my $index = <STDIN>)
{
    chomp $index;
    $at->setIteratorAtIndex($index);
    while (my $albumTrack = $at->nextItem())
    {
#        print "album id: " . $albumTrack->swig_album_id_get() . " track id: " . $albumTrack->swig_track_id_get() .  "\n";
        # !!! Notice how the wrapper uses the 'tie'-style iterface (ie. hash keys) to get to the struct fields.
        # !!! Or we can invoke the method it dreamt up (i.e. $obj->swig_album_id_get()).
        # !!! There must be a way to tell swig to rename the accessor methods (so I can use ->album_id instead of ->swig_album_id_get).
        # !!! Probably requires a directive for each field, but I can live with that.

        # !!! Actually, I just added public member functions to each 'struct' to return the field,
        # !!! and made the original fields private.   This causes SWIG to write the glue using
        # !!! the method names I prefer, and also prevents the ->{} notation from working at all (which is good).
        print "album id: " . $albumTrack->album_id . " track id: " . $albumTrack->track_id .  "\n";
    }
}

print("products\n");

my $products = StagedStaticData::ProductTable->new();
$products->loadDataFile("product");
print "num items: " . $products->numItems() . "\n";

while (my $index = <STDIN>)
{
    chomp $index;
    my $product = $products->getIndexedData($index);
    if ($product)
    {
    print "product_id : " . $product->product_id . "\n";
    print "upc_ean: " . $product->upc_ean . "\n";
    print "upc_alt: " . $product->upc_alt . "\n";
    print "product_type_id: " . $product->product_type_id . "\n";
    print "product_price_id: " . $product->product_price_id . "\n";
    print "product_status_id: " . $product->product_status_id . "\n";
    print "default_price_level_id: " . $product->default_price_level_id . "\n";
    print "asset_id: " . $product->asset_id . "\n";
    print "release_date: " . $product->release_date . "\n";
    }
    else
    {
    print "no such product...\n";
    }
}


print("sales\n");

my $sales = StagedStaticData::SaleTable->new();
$sales->loadDataFile("sale");
print "num items: " . $sales->numItems() . "\n";

while (my $index = <STDIN>)
{
    chomp $index;
    my $sale = $sales->getIndexedData($index);
    if ($sale)
    {
        print "sale_id: " . $sale->sale_id() . "\n";
        print "date_end: " . $sale->date_end() . "\n";
        print "product_type: " . $sale->product_type() . "\n";
        print "format_type: " . $sale->format_type()."\n";
        print "media_type: " . $sale->media_type(). "\n";
        print "units: " . $sale->units() . "\n";
        print "price: " . $sale->price(). "\n";
        print "sales: " . $sale->sales()."\n";
        print "returns: " . $sale->returns() . "\n";
        print "total_revenue: " . $sale->total_revenue() . "\n";
        print "channel: " . $sale->channel() . "\n";
        print "lic_track_id: " . $sale->lic_track_id() . "\n";
        print "product_id: " . $sale->product_id() . "\n";
    }
    else
    {
        print "no such sale...\n";
    }
}

