package RPS::Import::ADA::v29;
#
# This importer is not that similar v14.pm, but it maps a lot of
# formats similarly. It's also international and digital only, as
# opposed to domestic and int'l and physical (or at least that's
# what it looks like). We'll see how it goes.
#
use strict;

use lib '/app/tools/common/lib';
use lib '/app/tools/data_classes/lib';
use lib '/app/tools/rps/lib';
use RPS::File::Sale;
use RPS::Import::ServiceMap;

use base 'RPS::Import::ADA::v14';

sub _headerIdentifier { ( units => qr/^MONTHLY_UNITS$/ ) }

sub _fieldMap {
    {
        dateBegin   => 'A',
        serviceID   => 'D',
        countryCode => 'E',
        artistName  => 'F',
        trackName   => 'G',
        upc         => 'H',
        isrc        => 'H',
        units       => 'K',
        price       => 'L',
        labelName   => 'O',
        albumName   => 'Y',
    };
}

sub _unverifiedFieldMap {
    {
        deliveryFormat    => 'C',
        deliveryType      => 'AE',
        productIDTypeCode => 'I',
    };
}

sub albumName {
    return shift->_getByFieldName('albumName');
}

sub isrc {
    my $self = shift;

    my $isrc = $self->_getByFieldName('isrc') if ( $self->_getByFieldName('productIDTypeCode') =~ /^isrc$/i );

    return $isrc;
}

sub upc {
    my $self = shift;

    my $upc = $self->_getByFieldName('upc') if ( $self->_getByFieldName('productIDTypeCode') =~ /^upc$/i );

    return $upc;
}

sub _isValidSaleRecord {
    my $self  = shift;
    my $units = $self->units;
    my $price = $self->price;

    return undef if ( !$units && $price && $price < 0 );

    return $self->RPS::Import::Importer::_isValidSaleRecord();
}

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