package BookPub::Import::Importer::Acrobatiq::v1;

use strict;

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

use Date::Calc qw( Add_Delta_YM );

sub _headerIdentifier { rIsbn13 => 'eISBN' }

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            dateBegin    => 'C',
            rAuthor      => 'B',
            rTitle       => 'A',
            rIsbn13      => 'G',
            rInstitution => 'P',
            rState       => 'Q',
            rPostalCode  => 'R',
            countryCode  => 'S',
            rReturns     => 'E',
            rSales       => 'D',
            rUnits       => 'F',
            rListPrice   => 'I',
            rDiscount    => 'L',
            rRevenue     => 'M',
            currencyCode => 'N',
            rChannel     => 'O',
            rModel       => 'T',
        },
    );

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub currencyCode               { return shift->_getByFieldName("currencyCode") || "USD" }
sub countryCode                { return shift->_getByFieldName("countryCode")  || "US"  }
sub productType                { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rProductType               { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType               { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub rListPriceCurrency         { 'USD' }
sub priceType                  { 'rrp' }
sub rServiceName               { 'WGU' }

sub _isSaleRec {
    my $self = shift;

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

    # We're going to skip the subtotal line
    if ( lc($title) eq 'grand total' && !$date && !$author && !$isbn ) {
        return 0;
    }

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


1;