package BookPub::Import::Importer::Libri::Version1;

use strict;

use lib '/app/tools/common/lib';
use Common::Date;
use Common::Log;

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

sub _fieldMap {
    {
        # Data
        rServiceName => 'A',
        dateBegin    => 'C',
        rIsbn13      => 'E',
        rTitle       => 'G',
        rAuthor      => 'H',
        rUnits       => 'L',
        rListPrice   => 'M',
        rDiscount    => 'J',
        rRevenue     => 'I',

        # Currently, there is now country code.  But we want to know when they add one.
        countryCode => 'R',
    };
}

sub priceType    { 'rrp' }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub currencyCode { 'EUR' }

sub _headerIdentifier { ( rIsbn13 => 'ISBN13' ) }
sub _dateNormalization { 'month' }

sub rRevenue {
    my $self = shift;
    my $price = $self->_getByFieldName('rRevenue') || return;

    # Need to get rid of the euro formatting
    $price =~ s/\.//g;
    $price =~ s/,/\./g;

    return $price;
}

sub rListPrice {
    my $self = shift;
    my $price = $self->_getByFieldName('rListPrice') || return;

    # Need to get rid of the euro formatting
    $price =~ s/\.//g;
    $price =~ s/,/\./g;

    return $price;
}

sub countryCode {

    # Right now, there is no country code in the sales file,
    # so we are defaulting to Germany.
    # They will be adding one in the future though.
    # so we want to make sure that we notice the change.
    #
    my $self        = shift;
    my $countryCode = $self->_getByFieldName('countryCode');
    if ($countryCode) {
        die "Uknown data in column R";
    } else {
        return 'DE';
    }
}

1;
