package BookPub::Import::Importer::RedShelf::Version8;

use strict;

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

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        8 => {
            dateBegin            => 'B',
            rTitle               => 'F',
            rIsbn13              => 'G',
            rInstitution         => 'C',
            rListPrice           => 'I',
            rRevenue             => 'K',
            rTransactionCategory => 'L',
        },
    );

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

sub _unverifiedFieldMap {
    my $self = shift;

    # subtotal and unusedIsbn are used in isSaleRec
    my %fieldMap = (
        8 => {
            subtotal => 'A',
        },
    );

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub _headerIdentifier          { ( rIsbn13 => 'eISBN13' ) }
sub productType                { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType               { BookPub::DB::Item::Sale::kPurchaseTypeLoan }
sub countryCode                { 'US' }
sub currencyCode               { 'USD' }
sub rListPriceCurrency         { 'USD' }
sub units                      { return ( shift->rRevenue >= 0 ) ? 1 : -1 }

sub _getDateBegin {
    my $self      = shift;
    my $dateBegin = $self->_getByFieldName('dateBegin');

    return substr( $dateBegin, 0, 10 );
}

sub priceType {
    my $self = shift;

    my $type;
    my $clientID = Common::RSApp::GetClientID;

    if ( $clientID == 318 || $clientID == 310 ) {    # Macmillan is always agency
        $type = 'agency';
    } elsif ( $clientID == 346 ) {                   # RLPG
        $type = 'rrp';
    }

    return $type;
}

sub _isSaleRec {
    my $self = shift;

    # We're going to check for the subtotal line
    my $subtotal = $self->_getByFieldName('subtotal');
    if ( $subtotal =~ /^TOTALS?$/i ) {
        return 0;
    }

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

###
1;    #
###
