package BookPub::Import::Importer::Kinokuniya;

use strict;

use lib '/app/tools/common/lib';
use Common::Country;

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

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            dateBegin              => 'C',
            rAuthor                => 'G',
            rTitle                 => 'F',
            rIsbn13                => 'D',
            countryCode            => 'S',
            rUnits                 => 'I',
            rListPrice             => 'K',
            rListPriceCurrency     => 'J',
            rPurchasePrice         => 'P',
            rPurchasePriceCurrency => 'N',
            rDiscount              => 'L',
            rRevenue               => 'M',
            currencyCode           => 'J',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub _headerIdentifier { ( rIsbn13 => 'eISBN' ) }
sub _useIsSaleRec     { 1 }
sub priceType         { 'rrp' }
sub productType       { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType      { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub _autoParseTitleAndSubtitle { 1 }

sub _isSaleRec {
    my $self = shift;

    # We're going to check for the subtotal line, which is blank for these columns.
    my $date   = $self->_getByFieldName('dateBegin');
    my $isbn   = $self->_getByFieldName('rIsbn13');
    my $title  = $self->_getByFieldName('rTitle');
    my $author = $self->_getByFieldName('rAuthor');
    if ( !$date && !$isbn && !$title && !$author ) {
        return 0;
    }

    return $self->SUPER::_isSaleRec();
}

1;
