package BookPub::Import::Importer::OverDrive::Version6;

use strict;

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


sub _fieldMap {{
    dateBegin         => 'A',
    rFormat           => 'K',
    isbn              => 'D',
    rTitle            => 'E',
    rSubtitle         => 'F',
    rAuthor           => 'H',
    rListPrice        => 'L',
    rRevenue          => 'M',
}}

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

sub priceType { 'rrp' }
sub units        { 1 }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub currencyCode { 'USD' }
sub countryCode  { 'US' }

sub _isValidSaleRecord {
	return defined(shift->dateBegin());
}
sub formatType {
    my $self = shift;
    my $format = $self->rFormat() || return;

    $format  =~ /\s(\w+)\saudiobook/i;
    my $type = lc($1);

    if( $self->productType eq BookPub::DB::Item::Sale::kProductTypeAudioBook ) {
        return $type;
    } else {
        return $self->_parseFormat($format);
    }
}

sub productType {
    my $self = shift;
    my $format = $self->rFormat() || return;

    return BookPub::DB::Item::Sale::kProductTypeAudioBook if( $format =~ /audiobook/i );
    return BookPub::DB::Item::Sale::kProductTypeEBook if( $format =~ /ebook/i );

    return undef;
}

sub _isValidSaleRecord {
	my $self = shift;

	return $self->dateBegin && $self->rTitle;
}

1;
