package BookPub::Import::Importer::ProQuestSubscription::v18;

# this service of the importer has been renamed from Ebrary to ProQuestSubscription
# see RSD-4470

use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use parent 'BookPub::Import::Importer::ebrary::Version15';

sub _headerIdentifier { rTitle => 'Title' }
sub rListPriceCurrency { 'USD' }

sub _fieldMap {
    {
        rAuthor          => 'G',
        rTitle           => 'H',
        rIsbn13          => 'C',
        serviceProductID => 'A',
        rRevenue         => 'O',
    }
}

sub _getDateBegin {
    my $self = shift;

    my $filename = $self->filename;
    if ( $filename =~ /(Q[1-4])\-(20\d{2})/ ) {
        return $1 . '-' . $2;
    } elsif ( $filename =~ /(20\d{2})\-(Q[1-4])/ ) {
        return $2 . '-' . $1;
    }

    return;
}

sub serviceProductID {
    my $self = shift;

    my $serviceProductID = $self->_getByFieldName('serviceProductID') || 0;
    if ( $serviceProductID =~ /^[0-9.]+$/ ) {
        return sprintf "%d", $serviceProductID;
    }

    return $serviceProductID;
}


1;