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

use strict;

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

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

sub _fieldMap {
    {
        labelName     => 'C',
        dateBegin     => 'A',
        countryCode   => 'N',
        productType   => 'I',
        formatType    => 'J',
        artistName    => 'F',
        upc           => 'E',
        albumName     => 'G',
        isrc          => 'D',
        trackName     => 'H',
        currencyCode  => 'Q',
        units         => 'K',
        price         => 'Q'
    }
}

sub _headerIdentifier { ( upc => 'UPC' ) }
sub mediaType { RPS::DB::Item::MediaType::kMediaTypeAudio; }
sub serviceID { Client::Service::DSP_KKBOX_HONG_KING_LTD; }

sub _processHeader {
    my $self = shift;

    unless( $self->{_currencyCode} ) {
        my $st = $self->_getByFieldName('currencyCode');
        if( $st =~ /^(\w{3}) Payable$/i )
        {
            $self->{_currencyCode} = $1;
        }
    }
}

sub currencyCode{ shift->{_currencyCode} }

sub productType {
    my $self = shift;
    my $type = $self->_getByFieldName('productType');
    if( $type =~ /^track$/i )
    {
        return RPS::File::Sale::TYPE_TRACK;
    }
    $self->fail( "Could not determine type from $type");
}

sub formatType {
    my $self = shift;
    my $type = $self->_getByFieldName('formatType');
    if( $type =~ /^Streaming - (Monthly|Daily|Weekly)$/i ||
        $type =~ /^Streaming - Monthly\/Weekly\/Daily$/i ||
        $type =~ /^Sponsor$/i )
    {
        return RPS::File::Sale::FORMAT_STREAM;
    }
    elsif( $type =~ /^download$/i )
    {
        return RPS::File::Sale::FORMAT_DOWNLOAD;
    }
    $self->fail( "Could not determine format from $type");
}

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