package BookPub::Import::Importer::WesternInternational;

use strict;
use Data::Dumper;

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

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

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        4 => {
            dateBegin  => 'E',
            rTitle     => 'C',
            rIsbn13    => 'B',
            rUnits     => 'F',
            rUnitPrice => 'D',
            rListPrice => 'D',
            rRevenue   => 'G',
        },
    );

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

sub _unverifiedFieldMap {
    my $self = shift;

    my %fieldMap = (
        4 => {
            courseNumber => 'A',
        },
    );

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

sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType          { 'rrp' }
sub rInstitution       { 'Western International University' }
sub countryCode        { 'US' }
sub rListPriceCurrency { 'USD' }
sub currencyCode       { 'USD' }

sub _dateFormat                { ['numerical_year_first'] }
sub _autoParseTitleAndSubtitle { 1 }
sub _useIsSaleRec              { 1 }

sub _processLine {
    my $self   = shift;
    my $course = $self->_getByFieldName('courseNumber');

    if ( $course =~ /Total:/g ) {
        $self->{_endOfData} = 1;
        return;
    }

    return $self->SUPER::_processLine(@_);
}

sub _isSaleRec {
    my $self = shift;

    # If we've set the end of data flag in processLine, we are done.
    return if ( $self->{_endOfData} );

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

1;
