package BookPub::Import::Importer::Christianaudio::Version6;

use strict;

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

sub _headerIdentifier { ( rTitle => 'Title' ) }

sub _fieldMap {
    {
        # Header
        rProductType => 'E',

        # Data
        countryCode => 'O',
        rState      => 'M',
        rPostalCode => 'N',
        dateBegin   => 'C',
        rIsbn13     => 'E',
        rTitle      => 'F',
        rUnits      => 'P',
        rSales      => 'J',
        rReturns    => 'K',
        rListPrice  => 'G',
        rRevenue    => 'Q',
    };
}

sub priceType    { shift->{_priceType} }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub currencyCode { 'USD' }

sub _processHeader {
    my $self  = shift;
    my $field = $self->_getByFieldName('rProductType');

    if ( $field =~ /audiobook/i ) {
        $self->{_productType} = BookPub::DB::Item::Sale::kProductTypeAudioBook;
        $self->{_priceType}   = 'rrp';
    }

    if ( $field =~ /ebook/i ) {
        $self->{_productType} = BookPub::DB::Item::Sale::kProductTypeEBook;
        $self->{_priceType}   = 'agency';
    }
}

sub productType {
    my $self = shift;

    return $self->{_productType};
}

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