package BookPub::Import::Importer::InAudio::Version5;

use strict;

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

sub _headerIdentifier { ( rRevenue => 'Royalty Payable in USD' ) }

sub rListPriceCurrency { 'GBP' }
sub formatType         { return }

# we need to call these here to override the same sub in the base class

sub rDiscount {
    my $self = shift;

    my $discount = $self->_getByFieldName('rDiscount');
    return 1 - $discount;
}

sub productType {
    my $self = shift;

    my $productType = $self->_getByFieldName('rProductType');

    if ( $productType =~ /Audio/i ) {
        return BookPub::DB::Item::Sale::kProductTypeAudioBook;
    } elsif ( $productType =~ /eStories/i ) {
        return BookPub::DB::Item::Sale::kProductTypeAudioBook;
    }

    $self->fail("Unknown product type: $productType");
}

sub _processLine {
    my $self        = shift;
    my $productType = $self->_getByFieldName('rProductType');

    if ( $productType && $productType =~ /Grand Total/i ) {
        $self->{_endOfData} = 1;
    }

    return $self->SUPER::_processLine(@_);
}

1;
