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

package RPS::Import::Nimbit::v2;

use strict;

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

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

sub _fieldMap {
    {
        dateBegin        => 'E',
        productType      => 'G',
        upc              => 'AC',
        isrc             => 'AD',
        trackName        => 'H',
        albumName        => 'H',
        price            => 'M',
        units            => 'I',
    }
}

sub _headerIdentifier { ( upc => 'Upc' ) }
sub countryCode { 'US' }
sub currencyCode { 'USD' }

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

    if( $type =~ /^mp3 album$/i )
    {
        return RPS::File::Sale::TYPE_ALBUM;
    } 
    elsif( $type =~ /^mp3 download$/i )
    {
        return RPS::File::Sale::TYPE_TRACK;
    } 
    else
    {
        $self->fail( "Could not parse product type from '$type'" );
    }
}

sub formatType  {
    return RPS::File::Sale::FORMAT_DOWNLOAD;
}

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

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


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

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