package BookPub::Import::Importer::Chegg::Version16;

use strict;
use warnings;

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

sub _fieldMap {
    {
        dateBegin          => 'A',
        dateEnd            => 'A',
        purchaseType       => 'F',
        rAuthor            => 'J',
        rTitle             => 'G',
        rIsbn10            => 'L',
        rIsbn13            => 'K',
        rInstitution       => 'U',
        rState             => 'W',
        rPostalCode        => 'X',
        countryCode        => 'Y',
        rRevenue           => 'T',
        rListPrice         => 'P',
        rListPriceCurrency => 'P',
        rCOGS              => 'R',
        currencyCode       => 'T',
        rTaxAmount         => 'O',
        rDuration          => 'F',
        rPromoCode         => 'E',
    };
}

sub rServiceName {
    return BookPub::Tracker::Service::GetDefaultServiceName( service_id => shift->serviceID );
}

sub rFormat       { 'PDF' }
sub rPurchaseType { $_[0]->purchaseType }
sub rProductType  { $_[0]->productType }

sub purchaseType {
    my $self = shift;

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

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

sub rUnits {
    my $self = shift;

    my $revenue = $self->_getByFieldName('rRevenue') || 0;

    my $units = 0;
    $units = 1  if $revenue > 0;
    $units = -1 if $revenue < 0;

    return $units;
}

1;