package BookPub::Import::Importer::RedShelf::Version10;

use strict;
use warnings;

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

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        10 => {
            dateBegin       => 'B',
            rPurchaseType   => 'U',
            purchaseType    => 'U',
            rProductType    => 'T',
            rAuthor         => 'H',
            rTitle          => 'G',
            rIsbn13         => 'I',
            rImprint        => 'F',
            rInstitution    => 'E',
            rState          => 'AA',
            rPostalCode     => 'AB',
            countryCode     => 'AC',
            rListPrice      => 'K',
            rPurchasePrice  => 'L',
            rDiscount       => 'M',
            rRevenue        => 'O',
            rTaxAmount      => 'Q',
            rFee            => 'N',
            rDuration       => 'U',
            rDeliveryMethod => 'C',
        },
        14 => {
            dateBegin            => 'B',
            rPurchaseType        => 'U',
            purchaseType         => 'U',
            rProductType         => 'T',
            rAuthor              => 'H',
            rTitle               => 'G',
            rIsbn13              => 'I',
            rImprint             => 'F',
            rInstitution         => 'E',
            rState               => 'AA',
            rPostalCode          => 'AB',
            countryCode          => 'AC',
            rListPrice           => 'K',
            rPurchasePrice       => 'L',
            rDiscount            => 'M',
            rRevenue             => 'O',
            rTaxAmount           => 'Q',
            rFee                 => 'N',
            rDuration            => 'U',
            rDeliveryMethod      => 'X',
            rTransactionCategory => 'S',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub _unverifiedFieldMap {
    my $self = shift;

    # subtotal and unusedIsbn are used in isSaleRec
    my %fieldMap = (
        10 => {
            subtotal   => 'A',
            unusedIsbn => 'J',
            status     => 'R',
        },
        14 => {
            subtotal   => 'A',
            unusedIsbn => 'J',
            status     => 'S',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub rServiceName {
    return BookPub::Tracker::Service::GetDefaultServiceName( service_id => shift->serviceID );
}

sub priceType {
    my $self = shift;

    return $self->version == 14 && Common::RSApp::GetClientID =~ /^(?:314|328|361)$/ # Bloomsbury USA/WW/US
        ? 'agency'
        : $self->SUPER::priceType();
}

sub rSales  {
    my $self = shift;

    if ( $self->version == 10 ) {
        return $self->SUPER::rSales();
    }

    return undef;
}

sub rReturns {
    my $self = shift;

    if ( $self->version == 10 ) {
        return $self->SUPER::rReturns();
    }

    return undef;
}

sub rUnits {
    my $self = shift;

    if ( $self->version == 14 ) {
        my $rRevenue = $self->_getByFieldName('rRevenue') || 0;
        return $rRevenue < 0 ? -1 : 1;
    }

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


1;
