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

package RPS::Import::Merlin::v22;

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 {
    {
        dateBegin     => 'C',
        dateEnd       => 'D',
        countryCode   => 'B',
        labelName     => 'O',
        formatType    => 'E',
        productType   => 'F',
        artistName    => 'H',
        upc           => 'J',
        albumName     => 'L',
        isrc          => 'G',
        trackName     => 'I',
        units         => 'M',
        price         => 'Q',
    }
}

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

sub currencyCode { 'USD' }

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

sub serviceID { Client::Service::DSP_JBHIFIMUSIC }

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


sub formatType {
    my $self = shift;
    my $fmt = $self->_getByFieldName('formatType');
    if( $fmt =~ /^ps$/i )
    {
        return RPS::File::Sale::FORMAT_STREAM;
    }
    $self->fail("Unknown format type '$fmt'");
}

sub countryCode {
    my $self = shift;
    my $name = $self->_getByFieldName('countryCode');
    my $o = Common::Country->Get( $name );
    if( $o )
    {
        return $o->alpha2;
    }
    $self->fail("Unrecognized country '$name'");
}

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