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

use strict;

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

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

sub _fieldMap {
    {
        labelName    => 'F',
        countryCode  => 'Q',
        dateBegin    => 'B',
        formatType   => 'L',
        artistName   => 'G',
        upc          => 'I',
        albumName    => 'H',
        isrc         => 'K',
        trackName    => 'J',
        units        => 'N',
        currencyCode => 'T1',
        price        => 'T'
    };
}

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

sub formatType {
    my $self = shift;
    my $type = $self->_getByFieldName('formatType');
    if ( $type =~ /^Stream\s?$/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.
###
