package BookPub::Import::Importer::OLF::Version13;

use strict;

use lib '/app/tools/bookpub/lib';
use lib '/app/tools/common/lib';

use base 'BookPub::Import::Importer::OLF::Version12';

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        13 => {
            rAuthor                => 'J',
            rTitle                 => 'H',
            rSubtitle              => 'I',
            rIsbn13                => 'G',
            rImprint               => 'E',
            rInstitution           => 'D',
            countryCode            => 'B',
            rUnits                 => 'K',
            rUnitPrice             => 'P',
            rListPrice             => 'N',
            rListPriceCurrency     => 'L',
            rPurchasePrice         => 'M',
            rPurchasePriceCurrency => 'L',
            rDiscount              => 'O',
            rRevenue               => 'Q',
            currencyCode           => 'L',
        },
    );

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

sub _unverifiedFieldMap {
    my $self = shift;

    my %fieldMap = (
        13 => {
            month => 'A8',
            year  => 'A6',
        },
    );

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

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

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

sub priceType {
    my $self = shift;

    my $clientID = Common::RSApp::GetClientID;

    return 'agency'  if $clientID =~ /^355$/;                           # HUK
    return 'rrp+tax' if $clientID =~ /^359$/;                           # MMUK
    return 'rrp'     if $clientID =~ /^(?:314|328|361)$/;               # Bloomsbury

    if ( $clientID == 318 ) {
        return $self->countryCode =~ /^(?:US|CA)$/i ? 'agency' : 'rrp'; # MMUS
    }
}

sub rTaxUnitPrice {
    my $self = shift;

    return $self->_getByFieldName('rPurchasePrice') - $self->_getByFieldName('rListPrice');
}

sub rTaxAmount {
    my $self = shift;

    return $self->rTaxUnitPrice * $self->_getByFieldName('rUnits');
}


1;
