package BookPub::Import::Importer::Follett_Higher_Education::Version18;

use strict;

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

sub _headerIdentifier { ( rIsbn13 => 'ISBN' ) }

# map version num to the field order
sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        18 => {
            rIsbn13          => 'F',
            rInstitution     => 'B',
            serviceProductID => 'G',
            rReturns         => 'I',
            rUnitPrice       => 'H',
            rListPrice       => 'H',
            rRevenue         => 'J',
            rComments        => 'D',
        },
    );

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub _dateFormat                { ['text'] }
sub _dateNormalization         { 'month' }

sub purchaseType           { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType            { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rListPriceCurrency     { 'USD' }
sub rPurchasePriceCurrency { 'USD' }
sub currencyCode           { 'USD' }
sub countryCode            { 'US' }
sub priceType              { 'agency' }
sub rSales                 { 0 }
sub rModel                 { 'IncludED' }

sub _getDateBegin {
    my $self = shift;

    if ( $self->filename =~ /[ _](\w+)[ _](\d{4})\./ ) {
        return "$1 $2";
    } else {
        $self->fail( "Date not found in filename: " . $self->filename );
    }

}

sub _getDateEnd {
    my $self = shift;

    if ( $self->filename =~ /[ _](\w+)[ _](\d{4})\./ ) {
        return "$1 $2";
    } else {
        $self->fail( "Date not found in filename: " . $self->filename );
    }

}

1;
