package BookPub::Import::Importer::IngramDigital::Version6;

use strict;

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

sub _fieldMap {
    {
        rTitle       => 'A',
        rAuthor      => 'B',
        rIsbn13      => 'D',
        rListPrice   => 'G',
        dateBegin    => 'H',
        dateEnd      => 'H',
        rDiscount    => 'K',
        rUnits       => 'L',
        rRevenue     => 'M',
        currencyCode => 'N',
        countryCode  => 'Q',
    };
}

sub _unverifiedFieldMap {
    {
        softCoverISBN => 'E',
        hardCoverISBN => 'F',
    };
}

sub _headerIdentifier { ( rAuthor => 'AUTHOR' ) }

sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub formatType   { BookPub::DB::Item::Sale::kFormatTypeEPub }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType    { 'rrp' }
sub _dateFormat  { [ 'text', 'excel', 'numerical_year_first' ] }

sub rIsbn13 {
    my $self   = shift;
    my $isbn13 = $self->_getByFieldName('rIsbn13');

    # The digital ISBN column is sometimes blank.
    # When that happens, we'll try to use one of the physical ISBNs.
    #
    if ( !$isbn13 ) {
        $isbn13 = $self->_getByFieldName('softCoverISBN');
    }

    if ( !$isbn13 ) {
        $isbn13 = $self->_getByFieldName('hardCoverISBN');
    }

    return $isbn13;
}

1;

