package BookPub::Import::Importer::Chegg::Version17;

use strict;

use parent 'BookPub::Import::Importer::Chegg::Version13';

sub _fieldMap {
    {
        dateBegin            => 'B',
        dateEnd              => 'B',
        purchaseType         => 'L',
        rTitle               => 'E',
        rIsbn10              => 'H',
        rIsbn13              => 'G',
        rInstitution         => 'R',
        rState               => 'T',
        rPostalCode          => 'U',
        countryCode          => 'V',
        rRevenue             => 'P',
        rListPrice           => 'N',
        rDuration            => 'K',
        rTransactionCategory => 'L',
        rComments            => 'O',
    };
}

sub rServiceName { 'Chegg Inc.' }
sub rUnits { shift->units(); }
sub rListPriceCurrency { 'USD' }
sub currencyCode { 'USD' }
sub _processHeader { }; # overriding parent method because of new importer rules

sub rPurchaseType { shift->purchaseType() }

sub purchaseType {
    my $self = shift;

    my $type = $self->_getByFieldName('purchaseType') || '';
    return BookPub::DB::Item::Sale::kPurchaseTypeLoan     if $type =~ /^(?:rental|extension)$/i;
    return BookPub::DB::Item::Sale::kPurchaseTypeDownload if $type =~ /^sell$/i;

    $self->fail("Unknown purchase type '$type'.");
}

1;
