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

use strict;

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

#use lib '..';
use Common::RSMath;
use RPS::File::Sale;
use RPS::ArtistRoyalty::Fast::Static::Sales;
use RPS::ArtistRoyalty::Fast::Static::ProductTerms;
use RPS::ArtistRoyalty::Fast::Static::Terms;
use RPS::DB::Item::IncomeSource;
use RPS::DB::Item::PriceLevel;
use RPS::DB::Item::ContractRateType;
use RPS::ArtistRoyalty::Fast::TermType::Retail;
use RPS::ArtistRoyalty::Fast::TermType::Wholesale;
use RPS::ArtistRoyalty::Fast::TermType::PPD;
use RPS::ArtistRoyalty::Fast::TermType::Average;
use RPS::ArtistRoyalty::Fast::TermType::Revenue;
use RPS::ArtistRoyalty::Fast::TermType::GrossRevenue;
use RPS::ArtistRoyalty::Fast::TermType::Fixed;
use RPS::ArtistRoyalty::Fast::TermType::DocumentRetail;
use RPS::ArtistRoyalty::Fast::TermType::DocumentWholesale;
use RPS::ArtistRoyalty::Fast::TermType::NonPayable;

# This package will just be the Factory.
#

sub GetTermObj {
    my ( $class, $termID, $termData ) = @_;

    # !!! I don't want to waste time allocating memory to hold this data.
    # !!! I think I might be able to simply bless the term data reference.
    # !!! My goal here is to attach the correct methods to the data.
    #
    my $termRef = $termData->{$termID};
    Log->info( "GetTermObj : termRef = ", $termRef );

    my $rateType = $termRef->[RPS::ArtistRoyalty::Fast::Static::Terms::kContractRateTypeID];

    my $rateClass = (
          RPS::DB::Item::ContractRateType::kRateTypePercentRetail == $rateType            ? 'Retail'
        : RPS::DB::Item::ContractRateType::kRateTypePercentWholesale == $rateType         ? 'Wholesale'
        : RPS::DB::Item::ContractRateType::kRateTypePercentPPD == $rateType               ? 'PPD'
        : RPS::DB::Item::ContractRateType::kRateTypePercentAverage == $rateType           ? 'Average'
        : RPS::DB::Item::ContractRateType::kRateTypePercentRevenue == $rateType           ? 'Revenue'
	: RPS::DB::Item::ContractRateType::kRateTypePercentGrossRevenue == $rateType      ? 'GrossRevenue'
        : RPS::DB::Item::ContractRateType::kRateTypeFixed == $rateType                    ? 'Fixed'
        : RPS::DB::Item::ContractRateType::kRateTypePercentDocumentRetail == $rateType    ? 'DocumentRetail'
        : RPS::DB::Item::ContractRateType::kRateTypePercentDocumentWholesale == $rateType ? 'DocumentWholesale'
        : RPS::DB::Item::ContractRateType::kRateTypeNonPayable == $rateType               ? 'NonPayable'
        :                                                                                   undef
    );

    die "ERROR: No rate class for rate type '$rateType'  termID=$termID" unless $rateClass;

    $rateClass = "RPS::ArtistRoyalty::Fast::TermType::$rateClass";

    return bless $termRef, $rateClass;
}

1;
