package BookPub::Import::Importer::VitalSource::Version7;

use strict;

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

use Date::Calc qw( Add_Delta_YM );

sub _headerIdentifier { ( rUnits => 'QUANTITY' ) }

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

    my %fieldMap = (
        7 => {
            purchaseType => 'B',
            currencyCode => 'R',
            countryCode  => 'E',
            rPostalCode  => 'D',
            dateBegin    => 'F',
            dateEnd      => 'F',
            isbn         => 'H',
            rTitle       => 'G',
            rUnits       => 'L',
            rListPrice   => 'M',
            rDiscount    => 'N',
            rUnitPrice   => 'O',
            rRevenue     => 'Q',
            rDuration    => 'K',
            rInstitution => 'C',
        },
    );

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

sub rListPriceCurrency { 'USD' }

sub purchaseType {
    my $self     = shift;
    my $duration = $self->_getByFieldName('rDuration');

    if ( $duration eq '' || undef $duration ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeDownload;
    } else {
        return BookPub::DB::Item::Sale::kPurchaseTypeLoan;
    }
}

###
1;    #
###
