package BookPub::Import::Importer::Oyster::Version1;

use strict;
use Date::Calc qw(Days_in_Month Decode_Month);

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

sub _fieldMap {
    {
        # Detail
        dateBegin  => 'G',
        rIsbn13    => 'C',
        rTitle     => 'B',
        rAuthor    => 'D',
        rListPrice => 'E',
        rDiscount  => 'F',
        rRevenue   => 'H',
    };
}

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub purchaseType               { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub productType                { BookPub::DB::Item::Sale::kProductTypeEBook }
sub countryCode                { 'US' }
sub currencyCode               { 'USD' }

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

sub units { ( shift->rRevenue() < 0 ) ? -1 : 1 }

sub priceType {
    my $self     = shift;
    my $clientID = Common::RSApp::GetClientID;
    if ( $clientID == 314 ) {    # BBUS
        return 'rrp';
    } elsif ( $clientID == 328 ) {    # BBWW
        return 'rrp';
    } else {                          # Everybody else
        return 'agency';
    }
}

sub _isSaleRec {
    my $self = shift;

    my $date = $self->_getByFieldName('dateBegin');
    if ( lc($date) eq 'total due' ) {
        return;
    }

    return $self->SUPER::_isSaleRec();
}

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