package BookPub::Import::Importer::Follett_Higher_Education::Version6;

use strict;

use lib '/app/tools/common/lib';
use Common::Util;
use Common::Assert;

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

sub _fieldMap {
    {
        dateBegin  => 'C',
        rIsbn13    => 'E',
        rTitle     => 'K',
        rAuthor    => 'J',
        rSales     => 'L',
        rReturns   => 'L',
        rListPrice => 'M',
        rRevenue   => 'N',
    };
}

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

sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub priceType    { 'RRP' }
sub currencyCode { 'USD' }
sub countryCode  { 'US' }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }

sub rSales {
    my $self = shift;
    my $type = $self->_getByFieldName('rSales');

    ( $type eq 'Sale' || $type eq 'Sale Correction' || $type eq 'Standard' )
      ? return 1
      : return;

}

sub rReturns {
    my $self = shift;
    my $type = $self->_getByFieldName('rReturns');

    ( $type eq 'Refund' || $type eq 'Voided' )
      ? return 1
      : return;

}

sub rUnits {
    my $self = shift;

    if ( $self->rSales() ) {
        return 1;
    } elsif ( $self->rReturns() ) {
        return -1;
    } else {
        $self->fail("Can't determine units");
    }
}

###
1;    # Play nicely.
###
