package BookPub::Import::Importer::Bibliu::v2;

use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use parent 'BookPub::Import::Importer::Bibliu::v1';

sub _fieldMap {
    {
        dateBegin              => 'Z',
        dateEnd                => 'Z',
        purchaseType           => 'S',
        rFormat                => 'F',
        rTitle                 => 'C',
        rIsbn13                => 'E',
        rInstitution           => 'U',
        countryCode            => 'W',
        rReturns               => 'H',
        rSales                 => 'G',
        rUnits                 => 'I',
        rListPrice             => 'K',
        rListPriceCurrency     => 'M',
        rPurchasePrice         => 'O',
        rPurchasePriceCurrency => 'M',
        rDiscount              => 'N',
        rRevenue               => 'Q',
        currencyCode           => 'R',
        rFee                   => 'P',
        rDuration              => 'S',
        rTransactionCategory   => 'X',
    };
}

sub purchaseType {
    my $self = shift;

    my $type = $self->_getByFieldName('purchaseType') || '';
    if ( $type =~ /^Perpetual$/i ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL;
    } elsif ( $type =~ /^12 months?$/i ) {
        return BookPub::DB::Item::Sale::kPurchaseTypeLoan;
    }

    $self->fail("Unable to determine purchase type from '$type'.");
}


1;
