package BookPub::Import::Importer::SavantLearning;

use strict;

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

sub _headerIdentifier { ( rListPrice => 'Price' ) }

# map version num to the field order
sub _fieldMap {
    my $self = shift;

    my %fieldMap =
    (
		1 => {
            rServiceName         => 'B3',
            dateBegin            => 'D4',
            rTitle               => 'B',
            rInstitution         => 'B3',
            rUnits               => 'C',
            rListPrice           => 'D',
            rRevenue             => 'E',
	    },
		2 => {
            dateBegin            => 'E4',
            rServiceName         => 'B3',
            rTitle               => 'B',
            rInstitution         => 'B3',
            rIsbn13              => 'C',
            rUnits               => 'D',
            rListPrice           => 'E',
            rRevenue             => 'F',
	    },
    );

    return $fieldMap{$self->_version()};
}

sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType          { 'rrp' }
sub countryCode        { 'US' }
sub currencyCode       { 'USD' }
sub rListPriceCurrency { 'USD' }
sub rDiscount          { 0 }
sub _dateFormat        { ['us', 'iso'] }
sub _useIsSaleRec      { 1 }

sub _autoParseTitleAndSubtitle { 1 }
sub _useIsSaleRec  { 1 }

# sometimes the units field if blank, we'll return 0
sub rUnits {
    my $self = shift;
    my $revenue = $self->_getByFieldName( 'rRevenue' );
    my $units = $self->_getByFieldName( 'rUnits' );

    if ( $revenue == 0 && (!defined $units || $units eq '')) {
        return 0;
    }
    return $units
}

sub _isSaleRec {
    my $self = shift;

    return unless (
           $self->rUnits
        && $self->rRevenue
        && $self->rListPrice
    );

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

1;
