package RPS::Import::AmazonCloud::v2;

use strict;

use lib '/app/tools/rps/lib';
use base 'RPS::Import::Importer';

sub _fieldMap {
    {
        dateBegin        => 'D',
        serviceProductID => 'A',
        labelName        => 'G',
        artistName       => 'C',
        trackName        => 'B',
        units            => 'F',
        price            => 'J',
    }
}

sub _headerIdentifier { ( artistName => 'Composers' ) }

sub productType { RPS::File::Sale::TYPE_TRACK }

sub formatType { RPS::File::Sale::FORMAT_STREAM }

sub mediaType { RPS::DB::Item::MediaType::kMediaTypeAudio }

sub currencyCode { 'USD' }

sub countryCode { 'US' }

sub artistName {
    my $self = shift;
    my $name = $self->_getByFieldName('artistName');

    # If there's only one comma, then the name is probably in lastname, firstname
    # format, so we'll rearrange it so that it (hopefully) looks normal.
    # Otherwise, just pass it through as-is.
    #
    if( $name =~ /^([\w\s]+), ([\w\s]+)$/ )
    {
        return $2 . ' ' . $1;
    }
    return $name;
}

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