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

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 {
    my $self = shift;

    my %fieldMap = (
        1 =>  {
            dateBegin        => 'B1',
            dateEnd          => 'B2',
            serviceProductID => 'B',
            artistName       => 'E',
            isrc             => 'C',
            trackName        => 'D',
            price            => 'H',
            units            => 'F',
            currencyCode     => 'B4',
            countryCode      => 'A',
        },
        2 => {
            labelName        => 'K',
            countryCode      => 'A',
            dateBegin        => 'B1',
            dateEnd          => 'B2',
            serviceProductID => 'B',
            artistName       => 'E',
            upc              => 'J',
            isrc             => 'C',
            trackName        => 'D',
            units            => 'F',
            currencyCode     => 'I',
            price            => 'H',
        },
    );

    return $fieldMap{ $self->_version };
}

sub _headerIdentifier { ( isrc => 'ISRC' ) }

sub saleDates {
    my $self = shift;

    my $dateBegin;
    my $dateEnd;

    my $startDate = $self->_getDateBegin();
    my $endDate   = $self->_getDateEnd();

    if ( $startDate && $endDate ) {
        ( $dateBegin, $dateEnd ) = $self->_getDates( date_begin => $startDate, date_end => $endDate );
    }

    return ( $dateBegin, $dateEnd );
}

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

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

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

sub upc {
    my $self = shift;

    my $upc = $self->_getByFieldName('upc') || '';
    return $upc =~ /^.+_(.+)$/ ? $1 : undef;
}

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