package BookPub::Import::Importer::RedShelf::Version17;

use strict;

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

sub _fieldMap {
    {
        dateBegin            => 'B',
        rPurchaseType        => 'N',
        purchaseType         => 'N',
        rProductType         => 'M',
        rTitle               => 'F',
        rIsbn13              => 'G',
        rInstitution         => 'C',
        rState               => 'V',
        rPostalCode          => 'W',
        countryCode          => 'X',
        rClientProductID     => 'H',
        serviceProductID     => 'I',
        rUnits               => 'K',
        rUnitPrice           => 'K',
        rRevenue             => 'K',
        isFree               => 'E',
        rDuration            => 'N',
        rDeliveryMethod      => 'J',
        rModel               => 'M',
        rTransactionCategory => 'L',
        rComments            => 'R'
    }
}

sub _unverifiedFieldMap {
    {
        publisherNetCredit => 'K',
        status             => 'L',
        subtotal           => 'A',
        unusedIsbn         => 'J',
    }
}

sub rChannel { 'INCLUSIVE' }
sub rListPriceCurrencyCode { 'USD' }

sub rListPrice {
    my $self = shift;

    return $self->rUnitPrice() if (Common::RSApp::GetClientID =~ /^(?:346|324|318)$/ );    # Macmillan, Wiley, RLPG

    $self->SUPER::rListPrice();
}

sub countryCode {
    my $self = shift;

    my $country = $self->_getByFieldName('countryCode') || '';
    if ( !$country && Common::RSApp::GetClientID =~ /^(?:314|361|335|346|365)$/ ) {  # BBUS(A), BKPUB, RLPG, SAGE
        return 'US';
    }

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

sub purchaseType {
    my $self = shift;

    my $type = $self->_getByFieldName('purchaseType');
    if ( lc $type eq 'lifetime' ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeDownload;
    }

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


sub _isSaleRec {
    my $self = shift;

    my $isFree = $self->_getByFieldName('isFree') || '';
    my $publisherNetCredit = $self->publisherNetCredit();

    return 0 if ($isFree =~ /^STUDENT$/i && !$publisherNetCredit);

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

1;
