package BookPub::Import::Importer::Intel::Version6;

use strict;

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

use Date::Calc qw( Add_Delta_YM );

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        6 => {
            dateBegin  => 'B',
            dateEnd    => 'B',
            rTitle     => 'G',
            rIsbn13    => 'C',
            rState     => 'H',
            rListPrice => 'D',
            rDiscount  => 'F',
            rRevenue   => 'E',
        },
    );

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

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub _dateFormat                { 'iso' }

sub priceType          { 'rrp' }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub countryCode        { 'US' }
sub currencyCode       { 'USD' }
sub rListPriceCurrency { 'USD' }

sub rUnits {
    my $self = shift;

    my $revenue = $self->_getByFieldName('rRevenue');

    return $revenue < 0 ? -1 : 1;
}

sub _isSaleRec {
    my $self = shift;

    my $dateBegin = $self->_getByFieldName('dateBegin');
    my $isbn      = $self->_getByFieldName('rIsbn13');
    my $title     = $self->_getByFieldName('rTitle');
    my $author    = $self->_getByFieldName('rAuthor');
    my $state     = $self->_getByFieldName('rState');

    # We're going to skip the subtotal lines, which are blank for these fields
    if ( !$dateBegin && !$isbn && !$title && !$author && !$state ) {
        return 0;
    }

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

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