#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------
package RPS::Import::Universal::v34;

use strict;

use Date::Calc qw(Days_in_Month Decode_Month);

use lib '/app/tools/common/lib';
use Common::Country;
use Common::RSMath qw(round);

use lib '/app/tools/rps/lib';
use RPS::Import::ServiceMap;

use base 'RPS::Import::Universal::v33';

sub _fieldMap {
    {
        labelName    => 'B',
        serviceID    => 'H',
        dateBegin    => 'G',
        countryCode  => 'A',
        artistName   => 'E',
        productType  => 'I',
        formatType   => 'J',
        units        => 'M',
        price        => 'P',
        currencyCode => 'L',
    };
}

sub _unverifiedFieldMap {
    {
        itemID => 'D',    # upc or isrc
        title  => 'F',    # album or track name
    };
}

sub _headerIdentifier { ( dateBegin => 'Sales Period' ) }

sub currencyCode {
    return shift->RPS::Import::Importer::currencyCode();
}

sub albumName {
    my $self  = shift;
    my $title = $self->_getByFieldName('title');
    return $title if ( $self->productType eq RPS::File::Sale::TYPE_ALBUM );

    if ( !defined $self->productType ) {
        my $upc = $self->_getByFieldName('upc');
        $upc =~ s/^10//;    # remove leading "10"
        return $title if ( $upc =~ /^\d+$/ );    # if it's all numbers then it might be a UPC ...
    }
}

sub trackName {
    my $self  = shift;
    my $title = $self->_getByFieldName('title');
    return $title if ( $self->productType eq RPS::File::Sale::TYPE_TRACK );

    if ( !defined $self->productType ) {
        my $isrc = $self->_getByFieldName('itemID');
        $isrc =~ s/^5//;                         # remove leading "5"
        return $title if ( $isrc =~ /^[a-z]{2}/i );    # if it starts with 2 letters then it might be an ISRC ...
    }
}

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