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

package RPS::Import::Spotify::v3;

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,

        #detail
        countryCode => 0,
        labelName   => 1,
        formatType  => 2,
        upc         => 4,
        isrc        => 6,
        trackName   => 7,
        artistName  => 8,
        albumName   => 10,
        units       => 11,
        price       => 12,
    };
}

sub _unverifiedFieldMap {
    { ean => 5, };
}

# If we have set a currency code use it, otherwise use the base currency code.
sub currencyCode {
    my $self = shift;
    return $self->{_currencyCode}
      ? $self->{_currencyCode}
      : Common::Client::Current()->Locale()->currencyFormat()->currencyCode();
}

# For this version we need to check the header for a 'USD Payable' column.  If it
# exists our currency is USD.  Case 11968.
sub _processHeader {
    my $self = shift;

    my $header = $self->_getByFieldName('price');

    $self->{_currencyCode} = 'USD' if ( $header && $header eq 'USD Payable' );

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

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

    if ( $formatType =~ m/^1|10|100|15|40$/ ) {

        # See case 1929, 2276
        $formatType = RPS::File::Sale::FORMAT_VPD;
    } else {
        $formatType = RPS::File::Sale::FORMAT_STREAM;
    }

    return $formatType;
}

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

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

    return $upc;
}

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