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

package RPS::Import::YogiTunes::v1;

use strict;

use Date::Calc qw(Days_in_Month Decode_Month);

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

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

sub _fieldMap {
    {
    	labelName     => 'K',
        countryCode   => 'O',
        dateBegin     => 'H',
        dateEnd       => 'H',
        productType   => 'G',
        serviceProductID => 'N',
        artistName    => 'J',
        upc           => 'L',
        albumName     => 'I',
        isrc          => 'M',
        trackName     => 'I',
        currencyCode  => 'R',
        price         => 'Q',
    }
}

sub _headerIdentifier { ( countryCode => 'territory' ) }

sub units { 1 }
sub currencyCode { 'USD' }
sub formatType { RPS::File::Sale::FORMAT_DOWNLOAD }
sub mediaType { RPS::DB::Item::MediaType::kMediaTypeAudio }

sub productType {
    my $self = shift;
    my $type = $self->_getByFieldName( 'productType' ) || return;

    if( $type =~ /^track$/i ) {
        return RPS::File::Sale::TYPE_TRACK;
    } elsif( $type =~ /^album$/i ) {
        return RPS::File::Sale::TYPE_ALBUM;
    }

    $self->fail( "Could not parse product type from '$type'" );
}

sub albumName { 
	my $self = shift;
	my $albumName = $self->_getByFieldName( 'albumName' ) || return;    
	return $self->productType eq RPS::File::Sale::TYPE_ALBUM ? $albumName : undef;   
}

sub trackName { 
	my $self = shift;
	my $trackName = $self->_getByFieldName( 'trackName' ) || return;    
	return $self->productType eq RPS::File::Sale::TYPE_TRACK ? $trackName : undef;   
}



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