package BookPub::Import::Importer::CatchGroup;

use strict;

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

use Date::Calc qw( Add_Delta_YM );

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

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            countryCode    => 'P',
            dateBegin      => 'Q',
            rIsbn13        => 'C',
            rTitle         => 'B',
            rAuthor        => 'D',
            rSales         => 'E',
            rReturns       => 'R',
            rListPrice     => 'H',
            rPurchasePrice => 'G',
            rTaxAmount     => 'O',
            rRevenue       => 'N',

        },
    );

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

sub _unverifiedFieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            subtotal => 'A',
        },
    );

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub priceType                  { 'agency' }
sub currencyCode               { 'AUD' }
sub productType                { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType               { BookPub::DB::Item::Sale::kPurchaseTypeDownload }

sub _isSaleRec {
    my $self = shift;

    # We're going to check for the subtotal line
    my $subtotal = $self->_getByFieldName('subtotal');
    if ( $subtotal eq 'Total' ) {
        return 0;
    }

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

1;
