package BookPub::Import::Importer::Amazon::Version71;

use strict;
use warnings;

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


sub _fieldMap {
    {
        dateBegin                => 'A',
        purchaseType             => 'AD',
        rFormat                  => 'I',
        rAuthor                  => 'G',
        rTitle                   => 'F',
        rIsbn13                  => 'E',
        rImprint                 => 'H',
        countryCode              => 'V',
        serviceProductID         => 'B',
        rReturns                 => 'K',
        rSales                   => 'J',
        rUnits                   => 'L',
        rAdjustments             => 'N',
        rListPrice               => 'Q',
        rListPriceCurrency       => 'R',
        rNativeListPrice         => 'Q',
        rNativeListPriceCurrency => 'R',
        rPurchasePrice           => 'O',
        rPurchasePriceCurrency   => 'P',
        rDiscount                => 'S',
        rRevenue                 => 'T',
        currencyCode             => 'U',
        rIncentiveAmount         => 'X',
        rChannel                 => 'AD',
    };
}


sub priceType {
    my $self = shift;

    my $clientID = Common::RSApp::GetClientID();
    # MMUK
    if ( $clientID == 359 && $self->currencyCode =~ /^(?:GBP|EUR)$/i ) {
        return 'agencyplustax';
    }
    # HUK
    if ( $clientID == 355 ) {
        return 'agencyplustax';
    }

    return 'agency';
}

sub purchaseType {
    my $self = shift;

    my $type = $self->_getByFieldName('purchaseType') || '';
    if ( !$type || $type =~ /^(?:Vendor Funded Sales Promotion(?: ?; Bulk)?|Bulk)$/i ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeDownload;
    } elsif  ( $type =~ /^Lending( - Promo Period)?$/i ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeLoan;
    }
}

1;
