#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::ProductPrice;
use strict;
use warnings;
use lib '/app/tools/common/lib';
use Common::DB::Item;
use base 'Common::DB::Item';

use constant kTable => 'product_price';
use constant kDB    => Common::DB::Item::kClientDB();

sub GetByProductID {
    my ( $class, $productID ) = @_;

    my $sql = "SELECT * FROM " . kTable . " WHERE product_id=$productID";
    return $class->GetAll($sql);
}

sub GetByProductIDPriceLevelID {
    my ( $class, $productID, $priceLevelID ) = @_;

    $priceLevelID //= 0;
    my $sql = "SELECT * FROM " . kTable . " WHERE product_id=$productID AND price_level_id=$priceLevelID";

    my $collection = $class->GetAll($sql);

    # Should just be 1
    #
    return undef if ( 0 == $collection->size() );
    return $collection->next();
}

sub PriceIDCount {
    my ( $class, $priceID ) = @_;

    my $sql = "SELECT * FROM " . kTable . " WHERE price_id=$priceID";
    return $class->GetAll($sql)->size();
}

###
1;    #
###
