package BookPub::Import::Importer::LSI::Version3;

use strict;

use Common::Country;

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

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

sub _fieldMap {
    {
        currencyCode => 'AH',
        dateBegin    => 'AI',
        rFormat      => 'V',
        rIsbn10      => 'O',
        rIsbn13      => 'AP',
        rTitle       => 'B',
        rAuthor      => 'C',
        rImprint     => 'AJ',
        rUnits       => 'I',
        rListPrice   => 'W',
        rDiscount    => 'X',
        rRevenue     => 'N',
    };
}

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

sub priceType {
    if ( Common::RSApp::GetClientID == 308 ) {
        'agency';
    } else {
        'rrp';
    }
}

sub countryCode        { 'US' }
sub _dateNormalization { 'month' }

sub _getDateBegin {
    my $date = shift->SUPER::_getByFieldName('dateBegin');

    $date =~ s/^'// if ($date);

    return $date;
}

sub _parseFormat {
    my ( $self, $fmt ) = @_;
    my $format = $self->SUPER::_parseFormat($fmt);

    unless ($format) {

        # in LSI land, 'adobe ebook' is pdf
        $format = BookPub::DB::Item::Sale::kFormatTypePDF if ( $fmt =~ /adobe ebook/i );
    }

    return $format;
}

1;
