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

package RPS::Import::Merlin::v25;

use strict;

use Date::Calc qw(Days_in_Month Decode_Month);

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 {
    {
        labelName    => 'O',
        countryCode  => 'P',
        currencyCode => 'AC',
        dateBegin    => 'A',
        dateEnd      => 'B',
        productType  => 'R',
        artistName   => 'K',
        upc          => 'C',
        albumName    => 'M',
        isrc         => 'E',
        trackName    => 'L',
        units        => 'T',
        price        => 'AB',
    };
}

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

sub mediaType  { RPS::DB::Item::MediaType::kMediaTypeAudio; }
sub formatType { RPS::File::Sale::FORMAT_DOWNLOAD; }

sub serviceID { Client::Service::DSP_GOOGLE; }

sub productType {
    my $self = shift;
    my $type = $self->_getByFieldName('productType');
    if ( $type =~ /^track$/i ) {
        return RPS::File::Sale::TYPE_TRACK;
    } elsif ( $type =~ /^album$/i ) {
        return RPS::File::Sale::TYPE_ALBUM;
    }
    $self->fail("Unknown product type  '$type'");
}

sub units {
    my $self  = shift;
    my $units = $self->_getByFieldName('units');
    my $price = $self->_getByFieldName('price');
    if ( ( $price < 0 && $units > 0 ) || ( $price > 0 && $units < 0 ) ) {
        $units *= -1;
    }
    return $units;
}

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