package RPS::Import::Merlin::v47;
# Merlin/Yonder (ATO)

use strict;
use warnings;

use lib '/app/tools/rps/lib';

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

sub _fieldMap {
    {
        labelName    => 'D',
        countryCode  => 'M',
        dateBegin    => 'A',
        dateEnd      => 'B',
        productType  => 'G',
        formatType   => 'L',
        artistName   => 'H',
        albumName    => 'I',
        isrc         => 'G',
        trackName    => 'J',
        units        => 'N',
        price        => 'R',
    };
}

sub _headerIdentifier { isrc => 'Track ISRC No' }
sub serviceID         { Client::Service::DSP_YONDER }
sub currencyCode      { 'USD' }
sub mediaType         { RPS::DB::Item::MediaType::kMediaTypeAudio }

sub productType {
    return shift->isrc
        ? RPS::File::Sale::TYPE_TRACK
        : RPS::File::Sale::TYPE_ALBUM;
}

sub formatType {
    my $self = shift;

    my $type = $self->_getByFieldName('formatType') || '';

    if ( $type =~ /^stream$/i ) {
        return RPS::File::Sale::FORMAT_STREAM;
    }

    $self->fail("Unknown formatType '$type'");
}

sub countryCode {
    my $self = shift;

    my $country = $self->_getByFieldName('countryCode');
    my $oCountry = Common::Country->new( search => $country );
    return $oCountry->alpha2() if $oCountry;

    $self->fail("Unable to determine country code from '$country'");
}


1;
