package BookPub::Import::Importer::Readwell::Version2;

use strict;

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

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

sub _fieldMap {
    {
        # Detail
        rPriceType         => 'BN',
        serviceProductID   => 'S',
        isFree             => 'AE',
        currencyCode       => 'H',
        conversionRate     => 'BL',
        countryCode        => 'AH',
        dateBegin          => 'D',
        rProductType       => 'Z',
        rIsbn13            => 'R',
        rTitle             => 'T',
        rAuthor            => 'U',
        rImprint           => 'Y',
        rUnits             => 'AD',
        rSales             => 'AB',
        rReturns           => 'AC',
        rListPrice         => 'BM',
        rListPriceCurrency => 'AK',
        rDiscount          => 'AL',
        rUnitPrice         => 'AI',
        rRevenue           => 'AY',
    };
}

sub purchaseType {
    return BookPub::DB::Item::Sale::kPurchaseTypeDownload;
}

sub _isSaleRec {
    my $self = shift;

    return $self->BookPub::Import::Importer::_isSaleRec();
}

sub productType {
    my $self = shift;
    my $type = $self->rProductType;

    if ( !$type ) {
        return BookPub::DB::Item::Sale::kProductTypeEBook;
    }

    return $self->SUPER::productType();
}

sub isFree {
    my $self = shift;
    my $isFree = $self->_getByFieldName('isFree') || return;

    return $isFree;
}

###
1;    # Play nicely.
###
