#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------
package BookPub::RDAS::Process::BestSellerList;

use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tools/bookpub/lib';
use BookPub::Tracker::Service;
use BookPub::RDAS::Request::BestSellerList;
use BookPub::DB::Item::BestSellerList;

use base 'BookPub::RDAS::Process';

sub run_process {
    my $class = shift;
    my $self = ref($class) ? $class : $class->new(@_);

    my $singleton = Common::RSApp->new( clientID => 0 );

    $self->_process();
}

sub _jobClass { 'BookPub::RDAS::Job::FetchBestSellerList' }

sub _process {

    my $self = shift;
    my $row;

    my $request = BookPub::RDAS::Request::BestSellerList->GetRequestObject();

    # need to get the collection of all URLs from the best_seller_list
    # table and go through all of them

    my $collection = BookPub::DB::Item::BestSellerList->GetAllIDsAndUrls();

    if ( $collection->size() == 0 ) { return; }

    while ( $row = $collection->next() ) {
        Log->info("Processing list ID: $row->{best_seller_list_id}");
        $request->{_url} = $row->{url};
        $request->run() if ($request);
    }
}

1;
