#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2012 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package RPS::ArtistRoyalty::Fast::TermType::Retail;

use strict;

use lib '/app/tools/common/lib';
use lib '/app/tools/rps/lib';

use Common::Log;
use RPS::ArtistRoyalty::Fast::Static::ProductPrices;
use base 'RPS::ArtistRoyalty::Fast::TermType::Base';

sub _getPrice {
    my ( $self, $sale, $priceLevel, $productPrices ) = @_;

    my $priceData = $productPrices->{$priceLevel};
    if ( !$priceData ) {
        Log->info("No price data found for priceLevel: $priceLevel !!!");
        return undef;
    }

    return undef unless $priceData;

    return $priceData->[RPS::ArtistRoyalty::Fast::Static::ProductPrices::kRetail];
}

# Hmm... two issues really.  need to not log when price is 0.  but also need to NOT ACCUMULATE as well.

# !!! This should not be necessary, right?   Why do we even BOTHER to 'map' these reserves, only to ignore them later?
# !!! Instead we ought to recognize during MapReserves that a reserve is missing the required price AND SKIP IT.
sub _accumulateReserves {
    my ( $self, $data, $item ) = @_;

    if ( 0 != $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPrice] ) {
        $self->SUPER::_accumulateReserves( $data, $item );
    }
}

sub _createReserveLog {
    my ( $self, $data ) = @_;

    if ( 0 != $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPrice] ) {
        $self->SUPER::_createReserveLog($data);
    }
}

1;
