package BookPub::Import::Importer::Follett_Higher_Education::Version9;

use strict;

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

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

sub _fieldMap {
    {
        rState      => 'S',
        rPostalCode => 'T',
        dateBegin   => 'E',
        rIsbn13     => 'J',
        rTitle      => 'N',
        rAuthor     => 'M',
        rSales      => 'W',
        rReturns    => 'W',
        rListPrice  => 'X',
        rRevenue    => 'Y',
    };
}

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

sub _useIsSaleRec { 1 }

sub rTitle {
    my $title = shift->SUPER::rTitle;

    if ( $title =~ /^(.+) \(ebook\) \d+\w{2}$/ ) {
        $title = $1;
    }

    return $title;
}

sub rPostalCode {
    my $code = shift->SUPER::rPostalCode;

    return $code eq '0' ? undef : $code;
}

sub rState {
    my $state = shift->SUPER::rState;

    return !$state || $state eq 'NULL' || $state eq '(blank)' ? undef : $state;
}

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

    if ( $type eq 'Sale' || $type eq 'Sale Correction' ) {
        return 1;
    }
    return;
}

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

    if ( $type eq 'Refund' || $type eq 'Sale Reversal' ) {
        return 1;
    }
    return;
}

1;
