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

package RPS::Report::Dynamic::Transactions::USLicense;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use lib '/app/tools/rps/lib';
use lib '/app/tools/report/lib';
use Common::Client;
use RPS::DB::Item::DynamicReport::Transactions::USTrackLicense;

use base 'RPS::Report::Dynamic::Transactions::LicenseBase';

sub Type           { 'US License' }
sub FilenameType   { 'Transactions US License' }
sub ClientTypeMask { return Common::Client::kUSMechanicals; }

sub _getCollection {
    my $self = shift;

    my $dateType;
    my $dateTypeParam = $self->parameters()->{Criteria}->DateType();
    if ($dateTypeParam) {
        if ( 'Date Created' eq $dateTypeParam ) {
            $dateType = 'date_created';
        } elsif ( 'Date Modified' eq $dateTypeParam ) {
            $dateType = 'date_modified';
        }
    }

    # Need to determine whether we're sending processed or unprocessed
    my $transTypes = $self->parameters()->{OptionalData}->ReportType();

    my $processed   = 1 if ( 'All' eq $transTypes || 'Processed' eq $transTypes );
    my $unprocessed = 1 if ( 'All' eq $transTypes || 'Pending' eq $transTypes );

    return RPS::DB::Item::DynamicReport::Transactions::USTrackLicense->ReportQuery(
        dateType        => $dateType,
        startDate       => $self->parameters()->{Criteria}->StartDate(),
        endDate         => $self->parameters()->{Criteria}->EndDate(),
        showProcessed   => $processed,
        showUnprocessed => $unprocessed,

        #        showProcessed => $self->_showProcessed(),
        #        showUnprocessed => $self->_showUnprocessed(),
    );
}

sub _licenseTypeToString {
    my ( $self, %args ) = @_;
    my $rowItem   = $args{row};
    my $fieldName = $args{field};

    my $outString;
    my $typeID = $rowItem->$fieldName();

    if ($typeID) {
        $outString = 'US Mechanical'          if 1 == $typeID;
        $outString = 'Controlled Composition' if 2 == $typeID;
        $outString = 'Public Domain'          if 4 == $typeID;
        $outString = 'Ringtone'               if 5 == $typeID;
    }

    return $outString;
}

# Force the currency code to be 'USD'.
#
sub _appendCurrencyCode {
    my ( $self, $headerText ) = @_;

    return "$headerText (USD)";
}

1;
