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

use strict;

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

use base 'RPS::Import::Importer';

sub _fieldMap {
    {
        labelName    => 'E',
        countryCode  => 'Q',
        dateBegin    => 'B',
        dateEnd      => 'C',
        formatType   => 'K',
        artistName   => 'F',
        upc          => 'H',
        isrc         => 'J',
        trackName    => 'I',
        units        => 'M',
        currencyCode => 'T1',
        price        => 'T'
    };
}

sub _headerIdentifier { ( upc => 'release_id' ) }
sub _dateFormat       { 'eur' }
sub mediaType         { RPS::DB::Item::MediaType::kMediaTypeAudio; }
sub serviceID   { Client::Service::DSP_UMA; }      # !!!! Should be UMA!
sub productType { RPS::File::Sale::TYPE_TRACK; }

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

    if ( !$countryCode || $countryCode =~ /^OTHER$/i ) {
        return "EU";
    }

    return $countryCode;
}

sub formatType {
    my $self = shift;
    my $type = $self->_getByFieldName('formatType');
    if ( $type =~ /^ADFUNDED$/i ) {
        return RPS::File::Sale::FORMAT_STREAM;
    } elsif ( $type =~ /^SUBS$/i ) {
        return RPS::File::Sale::FORMAT_STREAM;
    }
    $self->fail("Could not determine format from $type");
}

sub currencyCode {
    my $self = shift;
    my $code = $self->_getByFieldName('currencyCode');
    if ( $code =~ /^Total in (\w{3})$/i ) {
        return $1;
    }
    $self->fail("Could not determine currency code from $code");
}

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