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

package RPS::Import::CricketMuve::v1;

use strict;

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

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

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

sub _fieldMap {
    {
        albumName    => 'N',
        artistName   => 'P',
        countryCode  => 'R',
        currencyCode => 'E',
        dateBegin    => 'D',
        formatType   => 'L',
        isrc         => 'C',
        labelName    => 'M',
        price        => 'I',
        productType  => 'K',
        serviceID    => 'Q',
        trackName    => 'O',
        units        => 'G',
        upc          => 'A',
    };
}

sub _headerIdentifier { ( dateBegin => 'date of transaction' ) }

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

sub productType {
    my $self = shift;
    my $type = $self->_getByFieldName('productType');

    if ( $type =~ m/^play$/i ) {
        return RPS::File::Sale::TYPE_TRACK;
    } else {
        $self->fail("Could not parse product type from '$type'");
    }
}

sub formatType {
    my $self       = shift;
    my $formatType = $self->_getByFieldName('formatType');

    my $format;
    if ( $formatType =~ m/^subscription$/i ) {
        $format = RPS::File::Sale::FORMAT_TETHERED;
    } else {
        $self->fail("Could not parse format type from '$formatType'");
    }
    return $format;
}

sub serviceID {
    my $self    = shift;
    my $service = $self->_getByFieldName('serviceID');

    my $serviceID;

    $serviceID = $self->getServiceID($service) || $RPS::Import::ServiceMap::SERVICE_ALIASES{ lc $service } if ($service);

    $self->fail("Unknown service '$service'") unless ($serviceID);

    return $serviceID;
}

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