package BookPub::Import::Importer::OCLC::Version3;

use strict;

use lib '/app/tools/bookpub/lib';
use base 'BookPub::Import::Importer::OCLC::Version1';

sub _fieldMap {
    {
        # Detail
        rPriceType           => 'AN',
        priceTypeQualifierID => 'Z',
        currencyCode         => 'I',
        countryCode          => 'AL',
        dateBegin            => 'O',
        rFormat              => 'AD',
        rIsbn13              => 'U',
        rTitle               => 'X',
        rAuthor              => 'Y',
        rImprint             => 'AB',
        rUnits               => 'BG',
        rUnitPrice           => 'AS',
        rSales               => 'BE',
        serviceProductID     => 'W',
        rReturns             => 'BF',
        rFee                 => 'BL',
        rModel               => 'Z',
        rListPrice           => 'AM',
        rListPriceCurrency   => 'AO',
        rDiscount            => 'AP',
        rRevenue             => 'BM',
    };
}

sub priceTypeQualifierID {
    my $self = shift;

    my $type = $self->_getByFieldName('priceTypeQualifierID') || '';

    # MMUK or MMUS
    if ( !$type && Common::RSApp::GetClientID =~ /^(?:359|318)$/ ) {
        return BookPub::DB::Item::PriceTypeQualifier::kCorporate;
    } elsif ( $type =~ /^PPU$/i ) {
        return BookPub::DB::Item::PriceTypeQualifier::kCorporate;
    }

    return;
}

sub rUnitPrice {
    my $self = shift;

    my $rUnitPrice = $self->_getByFieldName('rUnitPrice') || 0;
    my $rUnits = $self->_getByFieldName('rUnits')         || 0;

    if ( $rUnits ) {
        $rUnitPrice = $rUnitPrice / $rUnits;
    }

    return $rUnitPrice;
}

sub isFree {
    my $self = shift;

    return !$self->rRevenue && $self->rUnits ? 'Y' : 'N';
}

1;
