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

use strict;

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

sub _fieldMap {
    {
        # the next three are shifted by a row due to blank line at top of file
        dateBegin        => 'C3',
        dateEnd          => 'C4',
        currencyCode     => 'C5',

        labelName        => 'D',
        countryCode      => 'G',
        productType      => 'F',
        artistName       => 'B',
        upc              => 'A',
        isrc             => 'E',
        price            => 'J',
        units            => 'I',
    }
}

sub _unverifiedFieldMap {
   {
       title => 'C',
   }
}

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 albumName {
    my $self = shift;
    my $type = $self->_getByFieldName('productType');
    return $self->_getByFieldName('title') if($type =~ /^album$/i);
}

sub trackName {
    my $self = shift;
    my $type = $self->_getByFieldName('productType');
    return $self->_getByFieldName('title') if($type =~ /^track$/i);
}

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

    if( $type =~ /^album$/i )
    {
        return 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_DOWNLOAD; }

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

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