package BookPub::Import::Importer::VitalSource::Version13;

use strict;

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

sub _fieldMap {
    {
        rTitle             => 'E',
        rIsbn13            => 'G',
        rInstitution       => 'B',
        serviceProductID   => 'F',
        rUnits             => 'K',
        rListPrice         => 'L',
        rListPriceCurrency => 'O',
        currencyCode       => 'O',
        rDuration          => 'J',
    };
}

sub _unverifiedFieldMap {
    { amtDeducted => 'N', };
}

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

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }

sub countryCode  { 'US' }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType    { 'rrp' }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }

sub _dateNormalization { 'month' }

sub _getDateBegin {
    my $self     = shift;
    my $filename = $self->filename;

    if ( $filename !~ m/CodeSales\s+(\d{4}-\d{2})/ ) {
        $self->fail("Unrecognized date in filename: '$filename'");
    }

    return "$1-01";
}

sub rRevenue {
    my $self = shift;

    return $self->units * $self->listPrice - $self->_getByFieldName('amtDeducted');
}

1;

