package BookPub::Import::Importer::VitalSource::Version16;

use strict;

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

sub _fieldMap {
    {
        rTitle     => 'A',
        rUnits     => 'B',
        rListPrice => 'C',
        rRevenue   => 'D',
    };
}

sub _headerIdentifier { ( rRevenue => 'Revenue' ) }

sub rServiceName { 'VitalSource' }
sub priceType    { 'rrp' }
sub rInstitution { 'Western Governors University (WGU)' }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rProductType { shift->productType() }

sub countryCode  { 'US' }
sub currencyCode { 'USD' }
sub rListPriceCurrency { 'USD' }

my %months = (
    JAN => '01',
    FEB => '02',
    MAR => '03',
    APR => '04',
    MAY => '05',
    JUN => '06',
    JUL => '07',
    AUG => '08',
    SEP => '09',
    OCT => '10',
    NOV => '11',
    DEC => '12',
);
sub _getDateBegin {
    my $self     = shift;

    my $filename = $self->filename;
    if ( $filename !~ /\s(\w{3}) (\d{4})\.xlsx?$/ ) {
        $self->fail("Unrecognized date in filename: '$filename'");
    }

    return "$2-".$months{uc($1)};
}

sub _isSaleRec   {
    my $self = shift;

    my $title = $self->rTitle();
    return 0 if $title  =~ /^Grand Total$/;
    return 1;
}
1;
