package BookPub::Import::Importer::Perlego::Version3;

use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use parent 'BookPub::Import::Importer::Perlego::Version2';

sub _fieldMap {
    {
        dateBegin          => 'B',
        dateEnd            => 'C',
        rTitle             => 'H',
        rIsbn13            => 'I',
        countryCode        => 'K',
        serviceProductID   => 'A',
        rUnits             => 'J',
        rListPrice         => 'E',
        rListPriceCurrency => 'E',
        rRevenue           => 'G',
        currencyCode       => 'G',
    }
}

sub _processHeader {
    my $self = shift;

    if ( $self->_isHeader() ) {
        my $currency = $self->_getByFieldName('currencyCode') || '';
        $self->{_currency_code} = 'USD' if $currency =~ /\$$/;

        my $rListPriceCurrency = $self->_getByFieldName('rListPriceCurrency') || '';
        $self->{_r_list_price_currency_code} = 'GBP' if $rListPriceCurrency =~ /£$/;
    }

    return 1;
}

sub rListPriceCurrency { shift->{_r_list_price_currency_code} }
sub rUnits             { shift->_getByFieldName('rUnits') }

sub countryCode {
    my $self = shift;

    my $country = $self->_getByFieldName('countryCode') || '';

    return 'PS' if $country =~ /^Palestine/i;

    return $country;
}


1;