package BookPub::Import::Importer::Follett::Version4;

use strict;
use warnings;

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

sub _fieldMap {
    {
        dateBegin          => 'C1',
        rTitle             => 'D',
        rIsbn13            => 'C',
        rUnits             => 'I',
        rUnitPrice         => 'H',
        rListPrice         => 'F',
        rDiscount          => 'G',
        rRevenue           => 'J',
        rTransactionCategory => 'E3',
    }
}

sub _unverifiedFieldMap {{ }}

sub _headerIdentifier { rIsbn13 => 'eISBN' }

sub _useIsSaleRec      { 1 }
sub rServiceName       { 'Follett' }
sub _getDateBegin      { shift->{_dateBegin} }
sub currencyCode       { 'USD' }
sub rListPriceCurrency { 'USD' }
sub countryCode        { 'US' }
sub priceType          { 'RRP' }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }

sub _preProcess {
    my $self = shift;
    my %args = @_;

    $self->SUPER::_preProcess(%args);


    my $line = $args{sheets}->[0]->[0]->[2] || ""; # C1
    if ($line =~ /(\d{1,2}\/\d{1,2}\/\d{2,4})/ ) {
        my $date = Common::Date->new($1);
        $self->{_dateBegin} = $date;
    }
    else {
        $self->fail("Could not find date in line: $line");
    }
}

sub isFree {
    my $self = shift;

    return (((!$self->rRevenue || $self->rRevenue =~ /^0.0+/) && $self->rUnits) ? 'Y' : 'N');
}
sub _isSaleRec {
    my $self = shift;

    return if ( $self->rIsbn13() !~ /^\d+$/);

    return $self->SUPER::_isSaleRec();
}

1;
