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

use strict;
use warnings;
use Data::Dumper;

use lib '/app/tools/common/lib';
use lib '/app/tools/bookpub/lib';
use Common::Assert;
use Common::DB::Item;

use constant kTable => 'best_seller_monitor';
use constant kDB    => Common::DB::Item::kCommonDB();

use base 'Common::DB::Item';

sub GetAllByListIDOrderedByDatePosted {
    my ( $class, $listID ) = @_;
    assert($listID);

    my $sql = "SELECT * FROM " . kTable . " WHERE best_seller_list_id=$listID ORDER BY date_posted DESC";
    return $class->GetAll($sql);
}

sub GetMaxDatePostedByListID {
    my ( $class, $listID ) = @_;
    assert($listID);

    my $sql = " SELECT MAX(date_posted) AS max_date_posted FROM " . kTable . " WHERE best_seller_list_id=$listID";

    my $dbo = Common::RSApp::GetCommonDB();
    my $sth = $dbo->DoCmd($sql);
    my $hr  = $sth->fetchrow_hashref();
    return $hr->{max_date_posted};
}

1;
