package BookPub::Import::Importer::VitalSource::Version15;

use strict;

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

sub _fieldMap {
    {
        dateBegin            => 'B',
        purchaseType         => 'V',
        rAuthor              => 'T',
        rTitle               => 'S',
        rIsbn13              => 'Q',
        rInstitution         => 'G',
        rState               => 'I',
        rPostalCode          => 'J',
        countryCode          => 'K',
        serviceProductID     => 'P',
        rUnits               => 'Y',
        rUnitPrice           => 'AD',
        rListPrice           => 'AA',
        rListPriceCurrency   => 'Z',
        rDiscount            => 'AC',
        rRevenue             => 'AE',
        currencyCode         => 'AF',
        rDuration            => 'V',
        rDeliveryMethod      => 'F',
        rChannel             => 'E',
        rModel               => 'C',
        rTransactionCategory => 'D',
    };
}

sub _unverifiedFieldMap {
    {
        altInstitution => 'E',
        conversion     => 'AG',
    };
}

sub _headerIdentifier { ( rIsbn13 => 'EISBN' ) }

sub rIsbn13 {
    my $self = shift;

    my $isbn13 = $self->_getByFieldName('rIsbn13') || "";
    my $spid = $self->_getByFieldName('serviceProductID');

    return $isbn13 if $isbn13;

    # if isbn13 is empty, return service product id
    return $spid;
}

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

    if ( !$type ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeDownload;
    } else {
        return BookPub::DB::Item::Sale::kPurchaseTypeLoan;
    }
}

1;
