package BookPub::Import::Importer::VitalSource::Version21;

use strict;
use warnings;

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

# This importer is former Capella v1.
# It was renamed to Vital Source as part of RSD-6811


sub _fieldMap {
    {
        rServiceName         => 'G',
        dateBegin            => 'B',
        dateEnd              => 'B',
        rProductType         => 'R',
        priceType            => 'AD',
        rAuthor              => 'Z',
        rTitle               => 'Y',
        rIsbn13              => 'W',
        rInstitution         => 'G',
        rState               => 'I',
        rPostalCode          => 'H',
        countryCode          => 'J',
        serviceProductID     => 'X',
        rUnits               => 'AC',
        rUnitPrice           => 'AH',
        rListPrice           => 'AE',
        rListPriceCurrency   => 'AG',
        rRevenue             => 'AF',
        currencyCode         => 'AK',
        rTaxAmount           => 'AJ',
        rFee                 => 'AI',
        rDuration            => 'AB',
        rDeliveryMethod      => 'K',
        rTransactionCategory => 'C',
    };
}

sub _headerIdentifier { rProductType => 'CONTENT_TYPE' }

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }

sub productType   { shift->rProductType }
sub rProductType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeDownload }

sub rServiceName {
    my $self = shift;

    my $name = $self->_getByFieldName('rServiceName') || '';
    return 'Capella' if $name =~ /^Capella University$/i;

    $self->fail("Unable to determine rServeiceName from: '$name'.");
}

sub priceType {
    my $self = shift;

    my $type = $self->_getByFieldName('priceType');
    return 'rrp' unless $type;

    $self->fail("Unable to determine priceType from: '$type'.");
}


1;
