package BookPub::Import::Importer::Google::Version1;

use strict;

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

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

sub _fieldMap {
    {
        currencyCode => 'J',
        countryCode  => 'K',
        dateBegin    => 'A',
        rIsbn13      => 'G',
        rTitle       => 'B',
        rAuthor      => 'C',
        rListPrice   => 'H',
        rUnits       => 'E',
        rRevenue     => 'I',
    };
}

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

sub rRevenue {
    my $self = shift;

    my $revenue = $self->SUPER::rRevenue();
    my $units   = $self->units();

    return $units < 0 ? $revenue * -1 : $revenue;
}

sub _dateFormat { [ 'iso', 'us', 'excel' ] }

# For some reason when date is represented as an integer it is two dates off
sub _getDateBegin {
    my $date = shift->SUPER::_getDateBegin();
    return $date && $date =~ /^\d+$/ ? $date - 2 : $date;
}

1;
