package BookPub::Import::Importer::Feedbooks::Version2;

use strict;

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

sub _headerIdentifier { ( rTitle => 'Title' ) }

sub _fieldMap {
    {
        rPriceType     => 'G',
        currencyCode   => 'F',
        countryCode    => 'E',
        dateBegin      => 'D',
        rIsbn13        => 'A',
        rTitle         => 'B',
        rUnits         => 'C',
        rListPrice     => 'P',
        rPurchasePrice => 'I',
        rDiscount      => 'M',
        rRevenue       => 'O',
    };
}

sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType   { BookPub::DB::Item::Sale::kProductTypeEBook }
sub _useIsSaleRec { 1 }

sub _isSaleRec {
    my $self = shift;

    return $self->dateBegin;
}

sub rIsbn13 {
    my $self   = shift;
    my $number = $self->_getByFieldName('rIsbn13');

    $number =~ s/-//g;

    return $number;
}

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

    if ( $type eq 'wholesale' ) {
        return 'rrp';
    } elsif ( $type eq 'agency' ) {
        return 'agency';
    } else {
        $self->fail("Unexpected priceType found: $type ");
    }
}

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