package BookPub::Import::Importer::APUS::v3;

use strict;
use warnings;

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

sub _headerIdentifier { rTitle => 'Course Material/ISBN' }

sub _fieldMap {
    {
        dateBegin  => 'A',
        dateEnd    => 'B',
        rTitle     => 'F',
        rIsbn13    => 'F',
        rUnitPrice => 'H',
        rListPrice => 'H',
        rRevenue   => 'H',
    };
}

sub _useIsSaleRec      { 1 }
sub discount           { 0 }
sub rListPriceCurrency { 'USD' }
sub currencyCode       { 'USD' }
sub countryCode        { 'US' }
sub priceType          { 'rrp' }
sub rServiceName       { BookPub::Tracker::Service::GetDefaultServiceName( service_id => shift->serviceID ) }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub rPurchaseType      { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub productType        { BookPub::DB::Item::Sale::kProductTypePhysicalBook }
sub rProductType       { BookPub::DB::Item::Sale::kProductTypePhysicalBook }

sub rTitle {
    my $self = shift;

    my $rTitle = $self->_getByFieldName('rTitle') || '';
    $rTitle =~ /^\d*\s?(.*)$/;
    return $1;
}

sub rIsbn13 {
    my $self = shift;

    my $rIsbn13 = $self->_getByFieldName('rIsbn13') || '';
    $rIsbn13 =~ /^(\d{13})\s?.*$/;
    return $1;
}

sub rUnits {
    my $self = shift;

    my $rUnitPrice = $self->_getByFieldName('rUnitPrice') || 0;
    return $rUnitPrice <=> 0;
}

sub _isSaleRec {
    my $self = shift;

    return 1 if $self->rIsbn13 && $self->rUnitPrice && $self->rRevenue;
}

1;
