package BookPub::Import::Importer::Follett_Higher_Education::Version16;

use strict;

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

sub _headerIdentifier { ( rTitle => 'Title' ) }

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

    my %fieldMap = (
        16 => {
            dateBegin            => 'G',
            dateEnd              => 'G',
            rAuthor              => 'T',
            rTitle               => 'U',
            rIsbn10              => 'Q',
            rIsbn13              => 'R',
            rInstitution         => 'AC',
            rState               => 'AE',
            rClientProductID     => 'O',
            rUnits               => 'W',
            rListPrice           => 'Y',
            rPurchasePrice       => 'X',
            rRevenue             => 'Z',
            rDeliveryMethod      => 'AA',
            rChannel             => 'E',
            rTransactionCategory => 'V',
        },
    );

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub _dateFormat                { ['iso'] }

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

sub rUnits {
    my $self    = shift;
    my $units   = $self->_getByFieldName('rUnits');
    my $revenue = $self->_getByFieldName('rRevenue');

    if ( undef $units || $units eq '' ) {
        $units = 1;
    }

    if ( $revenue < 0 ) {
        return -1 * abs($units);
    }

    return $units;
}

1;
