package RPS::Import::ADA::v30;
#
# 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
{
    {    
        labelName   => 'T',
        serviceID   => 'E',
        countryCode => 'F',
        dateBegin   => 'A',
        artistName  => 'G',
        upc         => 'J',
        albumName   => 'Z',
        isrc        => 'J',
        trackName   => 'H',
        units       => 'N',
        price       => 'P',
    }
}

sub _unverifiedFieldMap
{
    {
        deliveryFormat      => 'D',
        deliveryType        => 'AI',
        productIDTypeCode   => 'K',
    }
}

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 $date = $self->dateBegin;
    my $service = $self->serviceID;
    my $units  = $self->units;
    my $price  = $self->price;

    return undef if ( !$date && !$service && !$units );

    return undef if ( !$units && $price && $price < 0 );
    
    return $self->RPS::Import::Importer::_isValidSaleRecord();
}


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