package BookPub::Import::Importer::OCLC::Version2;

use strict;

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

sub _fieldMap {
    {
        # Detail
        dateBegin  => 'F',
        rIsbn13    => 'C',
        rTitle     => 'D',
        rAuthor    => 'E',
        rUnits     => 'J',
        rListPrice => 'H',
        rDiscount  => 'I',
        rRevenue   => 'L',
    };
}

sub _headerIdentifier { ( dateBegin => 'PurchaseDate' ) }

sub _useIsSaleRec { 1 }
sub rServiceName  { "OCLC" }
sub currencyCode  { 'USD' }
sub countryCode   { 'US' }
sub priceType     { 'rrp' }
sub productType   { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeDownload }

sub _getDateBegin {
    my $self = shift;
    my $date = $self->_getByFieldName('dateBegin') || return;

    # the date is being returned in the "days since 1/1/1900" format, so we need
    # to convert it.  We'll check if it's a 5 digit number and greater than the
    # number of days since 1/1/1900 on 1/1/2006, which is 38716
    if ( $date =~ /^\d{5}$/ and $date > 38716 ) {
        $date = Spreadsheet::ParseExcel::Utility::ExcelFmt( "yyyy-mm-dd", $date );
        return $date;
    }

    return $date

}

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