package BookPub::Import::Importer::BolindaDigital::Version3;

use strict;

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

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

use Date::Calc qw( Add_Delta_YM );

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        3 => {
            currencyCode       => 'A7',
            countryCode        => 'A',
            dateBegin          => 'A3',
            dateEnd            => 'A3',
            rIsbn13            => 'C',
            rTitle             => 'E',
            rAuthor            => 'G',
            rImprint           => 'K',
            rUnits             => 'O',
            rListPrice         => 'M',
            rListPriceCurrency => 'A',
            rDiscount          => 'Q',
            rRevenue           => 'P',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub _unverifiedFieldMap {
    my $self = shift;

    my %fieldMap = (
        3 => {
            altCurrencyCode => 'A7',
            subtotal        => 'M',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub rDiscount {
    my $self     = shift;
    my $discount = $self->_getByFieldName('rDiscount');

    return $discount / 100;
}

sub rListPriceCurrency {
    my $self        = shift;
    my $country     = $self->_getByFieldName('rListPriceCurrency');
    my $countryCode = $Common::Consts::COUNTRY_CODE{ lc $country };
    if ( $countryCode eq "NZ" ) {
        return "AUD";
    }
    if ( $countryCode ne "" ) {
        my $currencyFormat = Common::CurrencyFormat->new( countryCode => $countryCode );
        my $currencyCode = $currencyFormat->currencyCode();
        return $currencyCode;
    }
    $self->fail("Unable to derive currency code from $country");
}

1;
