package BookPub::Import::Importer::JonathanBall::Version1;

use strict;

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

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

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

sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType          { 'rrp' }
sub currencyCode       { 'GBP' }
sub countryCode        { 'UK' }
sub _dateNormalization { 'month' }

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

        #Data
        rIsbn13    => 'A',
        rTitle     => 'B',
        rUnits     => 'C',
        rListPrice => 'D',
        rDiscount  => 'E',
        rRevenue   => 'F',
    };
}

sub _processHeader {
    my $self = shift;

    return if ( $self->{_dateBegin} );

    my $date = $self->_getByFieldName('dateBegin')
      || $self->fail("Date field in header empty");

    $date =~ /(\w+)\s+(\d+)/
      || $self->fail("Could not get date from '$date'");

    my $d = new Common::Date("$1 $2");
    $self->{_dateBegin} = "$d";
}

sub _getDateBegin { shift->{_dateBegin} }

1;
