package BookPub::Import::Importer::VitalSource::Version4;

use strict;

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

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

sub _fieldMap {
    {
        currencyCode => 'M',
        rIsbn13      => 'E',
        rTitle       => 'D',
        rUnits       => 'G',
        rListPrice   => 'H',
        rDiscount    => 'I',
        rUnitPrice   => 'J',
        rRevenue     => 'L',
    };
}

sub _dateNormalization { 'month' }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub priceType          { 'rrp' }
sub countryCode        { 'US' }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub _useIsSaleRec      { 1 }

sub _getDateBegin {
    my $self   = shift;
    my %months = (
        january   => 1,
        february  => 2,
        march     => 3,
        april     => 4,
        may       => 5,
        june      => 6,
        july      => 7,
        august    => 8,
        september => 9,
        october   => 10,
        november  => 11,
        december  => 12,
    );
    my $date = $self->filename;
    if ( $date !~ m/^(\d\d\d\d) (\w+)/ ) {
        $self->fail("Unrecognized date in filename: '$date'");
    }
    my $month = $months{ lc($2) };
    return "$1-$month-1";
}

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