package BookPub::Import::Importer::OverDrive::Version10;

use strict;

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

sub _fieldMap {
    {
        countryCode  => 'C',
        rState       => 'C',
        dateBegin    => 'K',
        rProductType => 'D',
        rFormat      => 'D',
        rIsbn13      => 'E',
        rTitle       => 'B',
        rListPrice   => 'G',
        rRevenue     => 'I',
    };
}

sub currencyCode {
    my $self = shift;
    unless ( exists $self->{_currencyCode} ) {
        my $clientID = Common::RSApp::GetClientID();
        if ( $clientID == 348 ) {
            $self->{_currencyCode} = "AUD";
        } else {

            $self->{_currencyCode} = 'GBP';
        }
    }
    return $self->{_currencyCode};
}

sub priceType {
    my $self = shift;
    unless ( exists $self->{_priceType} ) {
        my $clientID = Common::RSApp::GetClientID();
        if ( $clientID == 348 ) {
            $self->{_priceType} = "agency";
        } else {

            $self->{_priceType} = "rrp";
        }
    }
    return $self->{_priceType};
}

sub countryCode {
    my $self        = shift;
    my $countryCode = $self->_getByFieldName('countryCode');
    my $state       = $self->rState();

    if ($state) {
        return 'US';
    } elsif ( $countryCode =~ /\((\w{2})\)$/ ) {
        $countryCode = $1;

        # Let's see if this is a valid country code.
        if ( Common::Country->Get($countryCode) ) {
            return $countryCode;
        }
    }

    # If we couldn't figure it out above, just default to AU.
    return 'AU';
}

1;
