package BookPub::Import::Importer::VitalSource::Version10;

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 = (
        10 => {
            rServiceName           => 'C',
            currencyCode           => 'S',
            countryCode            => 'F',
            rPostalCode            => 'E',
            rIsbn13                => 'J',
            rTitle                 => 'H',
            rUnits                 => 'M',
            rListPrice             => 'N',
            rListPriceCurrency     => 'S',
            rPurchasePrice         => 'P',
            rPurchasePriceCurrency => 'S',
            rDiscount              => 'O',
            rRevenue               => 'R',
            rDuration              => 'L',
            rDeliveryMethod        => 'D',
            rTransactionCategory   => 'B',
            rInstitution           => 'C',
            serviceProductID       => 'I',
        },
    );

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

sub rProductType { shift->productType }

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;
    }
}

sub rServiceName {
    my $self = shift;

    my $serviceName = $self->SUPER::rServiceName();
    if ( lc($serviceName) ne 'barnes & noble education' ) {
        $serviceName = 'Vital Source';
    }

    return $serviceName;
}

sub priceType {
    my $self = shift;

    # MMUS
    if ( Common::RSApp::GetClientID == 318 ) {
        return 'agency';
    }

    return 'rrp';
}

###
1;    #
###
