package BookPub::Import::Importer::EBook::Version19;

use strict;

use lib '/app/tools/common/lib';
use Common::Country;

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

sub _fieldMap {
    {
        # Detail
        dateBegin          => 'O',
        dateEnd            => 'O',
        rFormat            => 'AD',
        priceType          => 'AK',
        rAuthor            => 'Y',
        rTitle             => 'X',
        rIsbn13            => 'U',
        rImprint           => 'AC',
        countryCode        => 'AL',
        rReturns           => 'AG',
        rSales             => 'AF',
        rUnits             => 'AH',
        rUnitPrice         => 'AM',
        rListPrice         => 'BQ',
        rListPriceCurrency => 'AO',
        rDiscount          => 'AP',
        rRevenue           => 'BC',
        currencyCode       => 'F',
        rFee               => 'AU',
    };
}

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub _headerIdentifier          { ( rTitle => 'ProductTitle' ) }
sub _dateFormat                { [ 'iso', 'numerical_year_first' ] }

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

sub rServiceName {
    return BookPub::Tracker::Service::GetDefaultServiceName( service_id => shift->serviceID );
}

sub rProductType { 'EBOOK' }

sub priceType {
    my $self = shift;

    my $type = $self->_getByFieldName('priceType') || '';
    return 'rrp'    if $type =~ /^Wholesale$/i;
    return 'agency' if $type =~ /^Agency$/i;

    $self->fail("Can't determine priceType from: '$type'.");
}

sub rFormat {
    my $self   = shift;
    my $format = $self->_getByFieldName('rFormat');

    if ( lc($format) eq 'e101' || lc($format) eq 'e107' ) {
        return BookPub::DB::Item::Sale::kFormatTypeEPub;
    }

    return $format;
}

1;
