package BookPub::Import::Importer::GooglePlay::Version1;

use strict;

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

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

sub _fieldMap {
    {
        currencyCode       => 'O',
        countryCode        => 'U',
        rState             => 'S',
        rPostalCode        => 'T',
        dateBegin          => 'B',
        rTitle             => 'G',
        rListPrice         => 'L',
        rListPriceCurrency => 'K',
        rPurchasePrice     => 'N',
        rRevenue           => 'Q',
    };
}

sub priceType    { 'rrp' }
sub formatType   { BookPub::DB::Item::Sale::kFormatTypeAndroidApp }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeInAppPurchase }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }

sub units {
    my $self = shift;

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

    if ( $revenue < 0 ) {
        $units = -1;
    }

    return $units;
}

sub _isValidSaleRecord {
    my $self = shift;

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

1;
