#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package RPS::Import::Spotify::v2;

use strict;

use lib '/app/tools/common/lib';
use Common::Assert;

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

sub _fieldMap {
    {
        #header
        dateBegin     => 1,
        dateEnd       => 2,
		    labelName     => 5,

        #detail
        countryCode   => 0,
        formatType    => 1,
        upc           => 3,
        isrc          => 5,
        trackName     => 6,
        artistName    => 7,
        albumName     => 9,
        units         => 10,
	}
}

sub _unverifiedFieldMap {{
        ean           => 4,
}}

sub labelName { shift->{_labelName} }

# If we have set a currency code use it, otherwise use the base currency code.
sub currencyCode {
	Common::Client::Current()->Locale()->currencyFormat()->currencyCode();
}

# 
sub formatType { 
	my $self = shift;
	my $formatType = $self->_getByFieldName( 'formatType' );    
	if ($formatType eq 'A')
	{
        $formatType = RPS::File::Sale::FORMAT_STREAM;
    }
    elsif ($formatType eq 'M')
    {
        $formatType = RPS::File::Sale::FORMAT_STREAM;
    }        
	elsif ($formatType eq 'U')
	{
        $formatType = RPS::File::Sale::FORMAT_STREAM;
    }
    elsif ($formatType eq 'P')
    {
        $formatType = RPS::File::Sale::FORMAT_STREAM;
    }  
	elsif ($formatType eq '1')
	{
        $formatType = RPS::File::Sale::FORMAT_VPD;
    }
    elsif ($formatType eq '10')
    {
        $formatType = RPS::File::Sale::FORMAT_VPD;
    }        
	elsif ($formatType eq '15')
	{
        $formatType = RPS::File::Sale::FORMAT_VPD;
    }
    elsif ($formatType eq '40')
    {
        $formatType = RPS::File::Sale::FORMAT_VPD;
    }     
    elsif ($formatType eq '100')
    {
        $formatType = RPS::File::Sale::FORMAT_VPD;
    }                     
    return $formatType;
}


sub upc { 
	my $self = shift;
	my $upc = $self->_getByFieldName( 'upc' );  
	
	if (!$upc)
	{
	    $upc = $self->_getByFieldName( 'ean' ); 
	}
	
    return $upc;
}

# In this version the labelName is stored in the header.
sub _processHeader {
	my $self = shift;

	if( $self->{_firstHeaderFound} ) {
		$self->{_label} = $self->_getByFieldName( 'labelName' );
	}

	return $self->SUPER::_processHeader(@_);
}

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