#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package Distribution::Metadata::ProductTrackList;
use strict;
use warnings;

use lib '/app/tools/Metadata/lib';
use Distribution::Metadata::ProductTrack;

use base 'Distribution::Metadata::ProductList';
use Common::Assert;

sub _init {
    my ( $self, %args ) = @_;

    my $trackID = $args{trackID};

    $self->{Product} = [];
    return $self if !defined $trackID;

    my $products = RPS::DB::Item::Product->GetProductsByTrackID($trackID);

    while ( $products->hasNext() ) {
        my $productData = $products->next();

        # we don't want the track products in the xml.
        # Note: we can always add a flag parameter to this function to control this behavior.
        #
        if ( RPS::DB::Item::Product::kProductTypeDigitalTrack == $productData->product_type_id ) {
            next;
        }

        push @{ $self->{Product} }, $self->_getProductXML($productData);
    }

    return $self;
}

sub _getProductXML {
    my ( $self, $productData ) = @_;
    return Distribution::Metadata::ProductTrack->new( _dbItem => $productData );
}

1;
