package BookPub::Import::Importer::Amazon::Version83;

use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use parent 'BookPub::Import::Importer::Amazon::Version64';

sub _fieldMap {
    {
        dateBegin                => 'A',
        dateEnd                  => 'A',
        rAuthor                  => 'C',
        rTitle                   => 'B',
        rIsbn13                  => 'D',
        countryCode              => 'H',
        serviceProductID         => 'G',
        rReturns                 => 'S',
        rSales                   => 'R',
        rUnits                   => 'T',
        rListPrice               => 'N',
        rListPriceCurrency       => 'O',
        rNativeListPrice         => 'L',
        rNativeListPriceCurrency => 'M',
        rPurchasePrice           => 'P',
        rPurchasePriceCurrency   => 'Q',
        rCOGS                    => 'J',
        rRevenue                 => 'U',
        currencyCode             => 'V',
        rChannel                 => 'I',
        rTransactionCategory     => 'K',
    }
}

sub _headerIdentifier { rIsbn13 => 'eISBN' }

sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType   { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rProductType  { BookPub::DB::Item::Sale::kProductTypeEBook }

sub countryCode {
    my $self = shift;

    my $code = $self->_getByFieldName('countryCode') || '';
    my ($countryCode) = $code =~ /(\w{2})/;

    return $countryCode;
}

sub currencyCode {
    my $self = shift;

    my $code = $self->_getByFieldName('currencyCode') || '';

    return $code;
}

sub isFree {
    my $self = shift;

    return !$self->rRevenue && $self->rUnits ? 'Y' : 'N';
}

sub _isSaleRec {
    my $self = shift;

    return unless $self->rRevenue || $self->rUnits || $self->rReturns || $self->rReturns;

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


1;
