package BookPub::Import::Importer::OneClickdigital::Version3;

use strict;

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

sub _fieldMap {
    {
        dateBegin            => 'E',
        dateEnd              => 'F',
        rProductType         => 'L',
        priceTypeQualifierID => 'C',
        rAuthor              => 'J',
        rTitle               => 'I',
        rIsbn13              => 'O',
        countryCode          => 'D',
        serviceProductID     => 'N',
        rUnits               => 'T',
        rAdjustments         => 'P',
        rListPrice           => 'U',
        rCOGS                => 'V',
        rRevenue             => 'X',
        currencyCode         => 'C',
    };
}

sub rListPriceCurrency     { 'GBP' }
sub rPurchasePriceCurrency { }

sub productType {
    my $self = shift;
    my $type = $self->_getByFieldName('rProductType');

    if ( lc($type) eq 'ebook' ) {
        return BookPub::DB::Item::Sale::kProductTypeEBook;
    }

    return;
}

sub priceTypeQualifierID {
    my $self = shift;
    my $id   = $self->_getByFieldName('priceTypeQualifierID');

    if ( $id =~ /^Pan Macmillan$/i ) {
        return BookPub::DB::Item::PriceTypeQualifier::kCorporate;
    }

    return;
}

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

    if ( $currency =~ /^Pan Macmillan$/i ) {
        return "GBP";
    } elsif ( $currency =~ /^Bloomsbury Publishing$/i ) {
        return "GBP";
    } elsif ( $currency =~ /^Pan Macmillan Australia$/i ) {
        return "AUD";
    }

    $self->fail("Unable to determine currency code for $currency");
}

1;
