package BookPub::Import::Importer::Follett_Higher_Education::Version14;

use strict;

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

sub _headerIdentifier { ( rTitle => 'Title' ) }

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

    my %fieldMap = (
        14 => {
            dateBegin            => 'D',
            dateEnd              => 'D',
            rAuthor              => 'J',
            rTitle               => 'K',
            rIsbn10              => 'G',
            rIsbn13              => 'F',
            rInstitution         => 'P',
            rState               => 'R',
            rListPrice           => 'N',
            rRevenue             => 'O',
            rChannel             => 'B',
            rTransactionCategory => 'C',
        },
    );

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

sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType          { 'rrp' }
sub countryCode        { 'US' }
sub currencyCode       { 'USD' }
sub rListPriceCurrency { 'USD' }
sub units              { return ( shift->rRevenue > 0 ) ? 1 : -1 }

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }

sub _getDateBegin {
    my $self = shift;
    my $date = $self->_getByFieldName('dateBegin');

    if ( !defined $date || $date eq '' ) {
        if ( $self->filename =~ /(\d{4})_(\d{2})/ ) {
            return "$1-$2-1";
        } else {
            $self->fail("Date not found in filename");
        }
    }
    return $date;
}

1;
