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

package RPS::Import::Addictech::v1;

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 {
    {
        labelName        => 'L',
        dateBegin        => 'G',
        dateEnd          => 'G',
        formatType       => 'O',
        artistName       => 'M',
        upc              => 'C',
        isrc             => 'B',
        trackName        => 'N',
        albumName        => 'K',
        price            => 'P',
        serviceProductID => 'E',
    }
}

sub units { 1; }

sub countryCode { 'US' }

sub currencyCode { 'USD' }

sub _headerIdentifier { ( dateBegin => 'Sale Timestamp' ) }

sub trackName {
    my $self = shift;
    my $isrc  = $self->_getByFieldName( 'isrc' );
    my $title = $self->_getByFieldName( 'trackName' );

    if( $isrc && $isrc ne "" )
    {
        return $title;
    } 
    return undef;
}

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

    if( $isrc && $isrc ne "" )
    {
        return RPS::File::Sale::TYPE_TRACK;
    } 
    else
    {
        return RPS::File::Sale::TYPE_ALBUM;
    }
}

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

    my $format;
    if( $formatType =~ m/^(192 kbps mp3|320 kbps mp3)$/i )
    {
        $format = RPS::File::Sale::FORMAT_DOWNLOAD;
    }
    elsif( $formatType =~ m/^(wav|flac)$/i )
    {
        $format = RPS::File::Sale::FORMAT_DOWNLOADPREMIUM;
    }
    else
    {
        $self->fail( "Could not parse format type from '$formatType'" );
    }
    return $format;
}

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

    my $mediaType;
    if( $formatType =~ m/^(192 kbps mp3|320 kbps mp3)$/i ||
        $formatType =~ m/^(wav|flac)$/i )
    {
        $mediaType = RPS::DB::Item::MediaType::kMediaTypeAudio;
    }
    else
    {
        $self->fail( "Could not parse media type from '$formatType'" );
    }
    return $mediaType;
}

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