package BookPub::Import::Importer::BookShout::Version4;

use strict;
use Data::Dumper;

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

sub _headerIdentifier { ( isbn => 'ISBN' ) }
sub _autoParseTitleAndSubtitle { 1 }
sub _useIsSaleRec              { 1 }
sub purchaseType               { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType                { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType                  { 'rrp' }
sub currencyCode               { 'USD' }
sub countryCode                { 'US' }
sub rDiscount                  { .4 }

sub _fieldMap {
    {
        serviceProductID => 'D',
        dateBegin        => 'B',
        dateEnd          => 'C',
        isbn             => 'F',
        rTitle           => 'E',
        rUnits           => 'H',
        rListPrice       => 'I',
        rRevenue         => 'J',
    };
}

sub _getDateBegin {
    my $self = shift;
    my $date = $self->_getByFieldName('dateBegin');

    if ( $date =~ m/(\d{4})(\d{2})(\d{2})/ ) {
        return $1 . '-' . $2 . '-' . $3;
    }
}

sub _getDateEnd {
    my $self = shift;
    my $date = $self->_getByFieldName('dateEnd');

    if ( $date =~ m/(\d{4})(\d{2})(\d{2})/ ) {
        return $1 . '-' . $2 . '-' . $3;
    }
}

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