package BookPub::Import::Importer::Amazon::Version56;

use strict;

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

sub _fieldMap {
    {
        serviceProductID       => 'G',
        currencyCode           => 'BF',
        countryCode            => 'Y',
        rState                 => 'W',
        rPostalCode            => 'X',
        dateBegin              => 'D',
        rIsbn13                => 'F',
        rTitle                 => 'H',
        rAuthor                => 'I',
        rUnits                 => 'K',
        rListPrice             => 'M',
        rListPriceCurrency     => 'N',
        rPurchasePrice         => 'O',
        rPurchasePriceCurrency => 'P',
        rModel                 => 'BI',
        rRevenue               => 'BE',
        rTaxAmount             => 'BG',
    };
}

sub _unverifiedFieldMap {
    {
        transactionStatus => 'L',
        transactionType   => 'R',
    };
}
sub rServiceName { 'Amazon' }
sub rProductType { shift->productType() }

sub rTransactionCategory {
    return shift->_getByFieldName('transactionStatus');
}
sub rTaxAmount {
    my $self            = shift;
    my $revenue         = $self->_getByFieldName('rRevenue') || 0;
    my $tax             = $self->_getByFieldName('rTaxAmount') || 0;
    my $transactionType = $self->_getByFieldName('transactionType');
    if ( ( $transactionType =~ /REFUND/i && $tax > 0 ) || ( $transactionType !~ /REFUND/i && $revenue < 0 ) ) {
        $tax = abs($tax) * -1;
	}
     return $tax;
}

sub countryCode {
    my $self = shift;

    my $code = $self->_getByFieldName('countryCode') || return 'US';

    return $code;
}

1;
