package BookPub::Import::Importer::IngramDigital::Version5;

use strict;

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

sub _fieldMap {
    {
        rIsbn13      => 'A',
        rTitle       => 'B',
        rAuthor      => 'C',
        rListPrice   => 'D',
        rUnits       => 'E',
        rRevenue     => 'K',
        currencyCode => 'L',
        rFormat      => 'M',
        countryCode  => 'N',
        dateBegin    => 'O',
    };
}

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

sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub formatType   { BookPub::DB::Item::Sale::kFormatTypeEPub }
sub priceType    { 'agency' }

sub _dateFormat { [ 'iso', 'text', 'excel' ] }

sub productType {
    my $self = shift;
    my $type = $self->rFormat();

    return unless ($type);

    if ( $type =~ /ebook/i ) {
        return BookPub::DB::Item::Sale::kProductTypeEBook;
    } else {
        die "Unknown product type '$type'";
    }
}

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

    # for some reason these ISBNs have leading quotes.
    return unless ($value);
    $value =~ s/'//g;

    return $value;
}

1;

