package BookPub::Import::Importer::Sony::Version8;

use strict;

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

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

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

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

sub _unverifiedFieldMap {
    { alternateDateBegin => 'M' };
}

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

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

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

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

sub _processHeader { shift->_storeDate() }

sub _storeDate {
    my $self = shift;

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

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

sub _getDateBegin { shift->{_dateBegin} }

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