package BookPub::Import::Importer::Sony::Version10;

use strict;

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

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

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

sub _fieldMap {
    {
        # Header
        dateBegin => 'M',

        # Data
        currencyCode       => 'L',
        countryCode        => 'K',
        rIsbn10            => 'G',
        rIsbn13            => 'H',
        rTitle             => 'I',
        rAuthor            => 'J',
        rUnits             => 'M',
        rListPrice         => 'E',
        rListPriceCurrency => 'D',
        rDiscount          => 'F',
        rRevenue           => 'N',
    };
}

sub _isValidSaleRecord {
    my $self = shift;
    return if ( $self->rListPriceCurrency eq 'Total' );

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

sub priceType    { 'rrp' }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }

sub rListPriceCurrency {
    my $self        = shift;
    my $country     = $self->_getByFieldName('rListPriceCurrency');
    my $countryCode = $Common::Consts::COUNTRY_CODE{ lc $country };
    if ( $countryCode ne "" ) {
        my $currencyFormat = Common::CurrencyFormat->new( countryCode => $countryCode );
        my $currencyCode = $currencyFormat->currencyCode();
        return $currencyCode;
    }
    return undef;
}

sub _dateNormalization { 'month' }
sub _dateFormat { [ 'excel', 'iso' ] }

sub _processHeader { shift->_storeDate() }

sub _storeDate {
    my $self = shift;

    unless ( $self->{_dateBegin} ) {
        $self->{_dateBegin} = $self->_getByFieldName('dateBegin');
    }
}

sub _getDateBegin { shift->{_dateBegin} }

###
1;    # Play nicely.
###
