package BookPub::Import::Importer::BookShout::Version3;

use strict;
use Data::Dumper;

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

sub _fieldMap {
    {
        rPriceType         => 'BR',
        currencyCode       => 'I',
        countryCode        => 'AL',
        dateBegin          => 'O',
        dateEnd            => 'P',
        rProductType       => 'T',
        rFormat            => 'AD',
        rClientProductID   => 'W',
        isbn               => 'U',
        rTitle             => 'X',
        rAuthor            => 'Y',
        rImprint           => 'AC',
        rUnits             => 'AH',
        rSales             => 'AF',
        rReturns           => 'AG',
        rListPrice         => 'BQ',
        rListPriceCurrency => 'AO',
        rPurchasePrice     => 'AM',
        rDiscount          => 'AP',
        rRevenue           => 'BC',
    };
}

sub _unverifiedFieldMap {
    {
        dateBegin2   => 'E',
        dateEnd2     => 'F',
        altPriceType => 'AN',
    };
}

# slight changes in this method, so I'm adding it here to overload the method in
# the parent clase (Base.pm)
sub priceType {
    my $self = shift;
    my $type = $self->_getByFieldName('rPriceType');

    if ( !$type && defined $self->_getByFieldName('altPriceType') ) {
        $type = $self->_getByFieldName('altPriceType');
    }

    if ( $type eq '01' || $type eq '1' || $type eq '02' || $type eq '11' ) {
        return 'rrp';
    }

    if ( $type eq '41' || $type eq '43' ) {
        return 'agency';
    }

    my $clientID = Common::RSApp::GetClientID();
    if ( !$type && $clientID == 346 ) {    # Setting RRP as the default for RLPG
        return 'rrp';
    }

    if ( !$type && $clientID == 318 ) {    # Setting Agency as the default for MacmillanUS
        return 'agency';
    }

    $self->fail("Unknown price type '$type'");
}

sub rListPrice {
    my $self = shift;
    my $price;

    my $clientID = Common::RSApp::GetClientID();
    if ( $clientID == 346 ) {
        $price = $self->_getByFieldName('rPurchasePrice');
    } else {
        $price = $self->_getByFieldName('rListPrice');
    }

    $price =~ s/\$//;

    return $price;
}

sub rPurchasePrice {
    my $self = shift;
    my $price;

    my $clientID = Common::RSApp::GetClientID();
    if ( $clientID != 346 ) {
        $price = $self->_getByFieldName('rPurchasePrice');
    }

    $price =~ s/\$//;

    return $price;
}

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