package BookPub::Import::Importer::Kobo::Version41;

use strict;
use warnings;

use lib '/app/tools/bookpub/lib';

use base 'BookPub::Import::Importer';

sub _fieldMap {
    {
        dateBegin          => 'A',
        rAuthor            => 'D',
        rTitle             => 'E',
        rIsbn13            => 'C',
        rImprint           => 'B',
        countryCode        => 'I',
        rUnits             => 'K',
        rListPrice         => 'G',
        rListPriceCurrency => 'H',
        rPurchasePrice     => 'F',
        rCOGS              => 'S',
        rRevenue           => 'T',
        currencyCode       => 'O',
    };
}

sub _headerIdentifier { rIsbn13 => 'eISBN' }

sub _useIsSaleRec { 1 }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub productType   { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType     { 'rrp' }

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

sub rTaxAmount {
    my $self = shift;

    my $rPurchasePrice = $self->rPurchasePrice || 0;
    my $rListPrice = $self->rListPrice         || 0;

    return $rPurchasePrice - $rListPrice;
}

sub isFree {
    my $self = shift;

    my $revenue = $self->_getByFieldName("rRevenue") || 0;
    my $units   = $self->_getByFieldName("rUnits")   || 0;

    return !$revenue && $units ? 'Y' : 'N';
}


1;
