package BookPub::Import::Importer::ZolaBooks::Version2;

use strict;

use lib '/app/tools/common/lib';

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

sub _headerIdentifier { ( rTitle => 'Title' ) }

sub _fieldMap {
    {
        countryCode    => 'M',
        rState         => 'N',
        rPostalCode    => 'P',
        rProductType   => 'F',
        dateBegin      => 'B',
        rIsbn13        => 'C',
        rTitle         => 'D',
        rAuthor        => 'E',
        rUnits         => 'G',
        rListPrice     => 'I',
        rCOGS          => 'L',
        rRevenue       => 'K',
        rTaxAmount     => 'Z'
    };
}

sub _useIsSaleRec { 1 }
sub priceType     { 'agency' }
sub rServiceName  { 'Zola Books' }
sub currencyCode  { 'USD' }
sub rRevenue      { return (shift->_getByFieldName('rRevenue') =~ s/[\$,]//gr) }
sub rListPrice    { return (shift->_getByFieldName('rListPrice') =~ s/^\$//gr) }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType   { shift->rProductType() }

sub rProductType   {
    return ( shift->_getByFieldName('rProductType') =~ /^ebook$/i ? BookPub::DB::Item::Sale::kProductTypeEBook : undef );
}

sub _isSaleRec {
    my $self = shift;
    return $self->rTitle && $self->dateBegin;
}

1;
