package BookPub::Import::Importer::HBG::Version3;

use strict;

use lib '/app/tools/bookpub/lib';

use base 'BookPub::Import::Importer::HBG::Version1';

sub _fieldMap {
    {
        rServiceName         => 'B',
        dateBegin            => 'D',
        rPriceType           => 'I',
        rAuthor              => 'L',
        rTitle               => 'O',
        rIsbn10              => 'K',
        rIsbn13              => 'J',
        countryCode          => 'A',
        rUnits               => 'Q',
        rListPrice           => 'P',
        rRevenue             => 'R',
        currencyCode         => 'R1',
        rChannel             => 'H',
        rTransactionCategory => 'F',
    };
}

sub rDistributor { 'HBG' }

sub priceType {
    my $self = shift;
    my $type = $self->rPriceType();

    if ( $type eq '01' ) {
        return 'rrp';
    }
    if ( $type eq '43' || $type eq '45' ) {
        return 'agency';
    }
    $self->fail("Unexpected price type value: $type");
}

sub currencyCode {
    my $self = shift;
    my $code = $self->_getByFieldName('currencyCode');

    if ( $code =~ / ([A-Z]{3}) / ) {
        return $1;
    }
    return;
}

1;
