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

use strict;

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

sub _fieldMap {
    {
        # the next three are all shifted 8 rows due to image at top of file
        dateBegin        => 'B3', # B11 in template
        dateEnd          => 'B4', # B12 in template
        currencyCode     => 'B5', # B13 in template

        labelName        => 'L',
        countryCode      => 'E',
        productType      => 'D',
        upc              => 'M',
        albumName        => 'J',
        isrc             => 'I',
        trackName        => 'F',
        units            => 'N',
        price            => 'O',
    }
}

sub _unverifiedFieldMap {
   {
       albumArtistName => 'K',
       trackArtistName => 'G',
   }
}

sub _headerIdentifier { ( upc => 'EAN/UPC' ) }

sub saleDates {
    my $self = shift;
    my $startDate = $self->_getDateBegin();
    my $endDate = $self->_getDateEnd();
    return $self->_getDates( date_begin => $startDate, date_end => $endDate );
}

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

    return ($type =~ /^track$/i) ? $self->_getByFieldName('trackArtistName') :
                                   $self->_getByFieldName('albumArtistName');
}

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

    if( $type =~ /^album$/i )
    {
        # sanity check - if the line is reporting isrc and track title then treat at track
        #
        my $isrc = $self->_getByFieldName('isrc');
        my $trackName = $self->_getByFieldName('trackName');
        return ($isrc && $trackName) ? RPS::File::Sale::TYPE_TRACK : RPS::File::Sale::TYPE_ALBUM;
    } 
    elsif( $type =~ /^track$/i )
    {
        return RPS::File::Sale::TYPE_TRACK;
    } 
    else
    {
        $self->fail("Could not parse product type from '$type'");
    }
}

sub formatType  { RPS::File::Sale::FORMAT_STREAM; }

sub mediaType { RPS::DB::Item::MediaType::kMediaTypeAudio; }

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