package BookPub::Import::Importer::Spotify::v1;

use strict;
use warnings;

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

sub _fieldMap {
    {
        dateBegin          => 'A',
        dateEnd            => 'B',
        rTitle             => 'F',
        rAuthor            => 'G',
        rIsbn13            => 'H',
        countryCode        => 'C',
        serviceProductID   => 'E',
        rUnits             => 'O',
        rListPrice         => 'L',
        rListPriceCurrency => 'K',
        rDiscount          => 'M',
        rRevenue           => 'R',
        currencyCode       => 'Q',
        rDuration          => 'J',
        rChannel           => 'D',
    };
}

sub _unverifiedFieldMap {{}}

sub _headerIdentifier { countryCode => 'Market' }

sub _useIsSaleRec { 1 }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeStream }
sub rPurchaseType { shift->purchaseType }
sub productType   { BookPub::DB::Item::Sale::kProductTypeAudioBook }
sub rProductType  { shift->productType }
sub priceType     { 'rrp' }
sub rServiceName { 'Spotify' }

sub units {
    my $self    = shift;
    my $units   = $self->_getByFieldName('rUnits') || 0;
    my $revenue = $self->_getByFieldName('rRevenue') || 0;

    return 1 if ($revenue || !$revenue)  && !$units;
    return $units;
}

sub isFree {
    my $self = shift;

    return !$self->rRevenue && ($self->rUnits || !$self->rUnits) ? 'Y' : 'N';
}

1;
