package BookPub::Import::Importer::WFHowes::v8;

use strict;
use warnings;

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

sub _fieldMap {
    {
        dateBegin            => 'H',
        dateEnd              => 'H',
        rProductType         => 'B',
        priceTypeQualifierID => 'J',
        rAuthor              => 'D',
        rTitle               => 'C',
        rIsbn13              => 'E',
        rInstitution         => 'G',
        countryCode          => 'G',
        serviceProductID     => 'I',
        rUnits               => 'P',
        rListPrice           => 'M',
        rListPriceCurrency   => 'L',
        rRevenue             => 'Q',
        currencyCode         => 'L',
    };
}

sub _headerIdentifier { rIsbn13 => 'ISBN' }

sub _useIsSaleRec        { 1 }
sub priceType            { 'rrp' }
sub purchaseType         { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub priceTypeQualifierID { BookPub::DB::Item::PriceTypeQualifier::kCorporate }
sub rServiceName         { 'W.F. Howes' }

sub rProductType         { shift->productType() }
sub productType {
    my $self = shift;

    my $type = $self->_getByFieldName("rProductType") || "";
    return BookPub::DB::Item::Sale::kProductTypeEBook if $type =~ /^ebook$/i;

    $self->fail("Cannot determine product type from '$type'");
}

sub _isSaleRec {
    my $self = shift;

    return $self->rIsbn13 && $self->rUnits;
    return $self->SUPER::_isSaleRec();
}

1;
