package BookPub::Import::Importer::MaruzenYushodo::v1;

use strict;
use warnings;

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

sub _fieldMap {
    {
        rServiceName       => 'K2',
        dateBegin          => 'J',
        rTitle             => 'C',
        rIsbn13            => 'B',
        rInstitution       => 'K',
        countryCode        => 'L',
        rUnits             => 'H',
        rUnitPrice         => 'G',
        rListPrice         => 'E',
        rListPriceCurrency => 'E',
        rCOGS              => 'F',
        rRevenue           => 'I',
        currencyCode       => 'I',
    };
}

sub _unverifiedFieldMap {{
        _num               => 'A',
    }}

sub _headerIdentifier { rTitle => 'Title' }

sub _useIsSaleRec      { 1 }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rPurchaseType      { $_[0]->purchaseType() }
sub rProductType       { $_[0]->productType() }
sub rPriceType         { $_[0]->priceType() }
sub rListPriceCurrency { $_[0]->currencyCode() }
sub priceType          { 'rrp' }

sub currencyCode {
    my $self = shift;
    return $self->{_currencyCode};
}

sub _processHeader {
    my $self   = shift;
    my $code = $self->_getByFieldName('currencyCode') || '';

    if ( $code =~ /^(\w{3})\s/i ) {
        $self->{_currencyCode} = $1;
    }
    return $self->SUPER::_processHeader(@_);
}

sub isFree {
    my $self = shift;

    return !$self->rRevenue && $self->rUnits ? 'Y' : 'N';
}

sub _isSaleRec {
    my $self = shift;

    my $num = $self->_getByFieldName("_num") || "";
    return ($num && $num !~ /total/i) && $self->dateBegin;
}

1;
