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

package RPS::Import::Real::v6;

use strict;

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

use lib '/app/tools/rps/lib';
use RPS::Import::ServiceMap;

use base 'RPS::Import::Importer';

sub _fieldMap {
    {
        dateBegin => 'Q',
        dateEnd   => 'R',

        labelName        => 'A',
        serviceProductID => 'O',
        artistName       => 'C',
        upc              => 'F',
        albumName        => 'D',
        isrc             => 'I',
        trackName        => 'E',
        units            => 'J',
        price            => 'L',

        formatType => 'J',
    };
}

sub productType { RPS::File::Sale::TYPE_TRACK }

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

sub countryCode  { 'US' }
sub currencyCode { 'USD' }

sub formatType {
    my $self = shift;
    return $self->{_formatType} if ( $self->{_formatType} );
}

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

sub _preProcess {
    my $self = shift;
    my %args = @_;

    Log->info("Starting _preProcess");
    $self->SUPER::_preProcess(%args);

    my $formatColumn;

    my $linenum = 0;
    foreach my $line ( @{ $args{lines} } ) {
        $self->{line} = $line;

        $formatColumn = $self->_getByFieldName('formatType');
        if ( $formatColumn =~ /^# (\w+)/i ) {
            if ( $1 =~ /^streams$/i ) {
                $self->{_formatType} = RPS::File::Sale::FORMAT_STREAM;
                last;
            } else {
                $self->fail("Unknown format '$1'");
            }
        }
        $linenum++;
    }
}

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