package BookPub::Import::Importer::Amazon::Version36;

use strict;

use lib '/app/tools/common/lib';
use Common::Country;

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

sub _fieldMap {
    {
        rPurchaseType    => 'P',
        serviceProductID => 'C',
        currencyCode     => 'V',
        dateBegin        => 'B',
        rFormat          => 'J',
        isbn             => 'F',
        rTitle           => 'G',
        rAuthor          => 'H',
        rImprint         => 'I',
        rUnits           => 'M',

        #rSales             => 'K', # can't pull these because of the need to flip units
        #rReturns           => 'L', # can't pull these because of the need to flip units
        rAdjustments => 'N',
        rListPrice   => 'W',

        #rCOGS              => 'X', # unreliable, so we'll always calculate
        rRevenue => 'Z',
    };
}

sub _useIsSaleRec { 1 }

sub rUnits {

    # We need to make sure that the sign of the units matches the sign of the revenue
    my $self    = shift;
    my $units   = $self->_getByFieldName('rUnits');
    my $revenue = $self->rRevenue;

    if ( ( $revenue < 0 && $units > 0 ) || ( $revenue > 0 && $units < 0 ) ) {
        $units *= -1;
    }

    return $units;
}

1;
