package BookPub::Import::Importer::Downpour;

use strict;

use lib '/app/tools/bookpub/lib';
use base 'BookPub::Import::Importer';

use Date::Calc qw( Add_Delta_YM );

# map version num to the field order
sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            dateBegin        => 'A',
            dateEnd          => 'A',
            rAuthor          => 'E',
            rTitle           => 'D',
            rIsbn13          => 'F',
            serviceProductID => 'C',
            rUnits           => 'G',
            rListPrice       => 'H',
            rRevenue         => 'I',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub _headerIdentifier { ( rIsbn13 => 'ISBN13' ) }
sub _useIsSaleRec { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub _dateFormat                { 'excel' }
sub _dateNormalization         { 'month' }

sub currencyCode       { 'USD' }
sub rListPriceCurrency { 'USD' }
sub countryCode        { 'US' }
sub productType        { BookPub::DB::Item::Sale::kProductTypeAudioBook }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub priceType          { 'rrp' }

sub _isSaleRec {
    my $self = shift;

    my $date = $self->_getByFieldName('dateBegin');

    # We're going to skip the subtotal line
    if ( $date =~ /total/i ) {
        return 0;
    }

    return $self->SUPER::_isSaleRec();
}

###
1;    #
###
