package BookPub::Import::Importer::LibraryIdeas;

use strict;

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

sub _fieldMap {
    {
        dateBegin  => 'A1',
        rTitle     => 'B',
        rIsbn13    => 'A',
        rImprint   => 'C',
        rUnits     => 'E',
        rListPrice => 'G',
        rRevenue   => 'H',
    };
}

sub _headerIdentifier { ( rIsbn13 => 'ISBN' ) }

sub _useIsSaleRec { 1 }

sub countryCode        { 'US' }
sub currencyCode       { 'USD' }
sub rListPriceCurrency { 'USD' }
sub productType        { BookPub::DB::Item::Sale::kProductTypeEBook }
sub priceType          { 'rrp' }
sub purchaseType       { BookPub::DB::Item::Sale::kPurchaseTypeLoan }

sub _isSaleRec {
    my $self = shift;

    return $self->rIsbn13 && $self->rRevenue != 0;
}

sub _dateNormalization { 'month' }

sub _getDateBegin {
    my $self = shift;

    my ($date) = $self->_getByFieldName('dateBegin') =~ /^(\w+\s+\d{4})\s+/;

    return $date;
}

sub rIsbn13 {
    my $self = shift;

    my $isbn13 = $self->_getByFieldName('rIsbn13');
    $isbn13 =~ s/-//g;

    return $isbn13;
}

sub rRevenue {
    my $self = shift;

    my ($revenue) = $self->_getByFieldName('rRevenue') =~ /^\$?(.*)$/;

    return $revenue;
}

sub rListPrice {
    my $self = shift;

    my ($listPrice) = $self->_getByFieldName('rListPrice') =~ /^\$?(.*)$/;
    my $units = $self->rUnits;

    $listPrice /= $units if $units;

    return $listPrice;
}

1;

