package RPS::Import::Merlin::v68;

use strict;
use warnings;

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

use parent qw/RPS::Import::MapFaceBase RPS::Import::Merlin::v38/;

sub _fieldMap {
    {
        labelName    => 'E',
        dateBegin    => 'B',
        countryCode  => 'Q',
        productType  => 'L',
        formatType   => 'M',
        artistName   => 'H',
        upc          => 'G',
        albumName    => 'I',
        isrc         => 'F',
        trackName    => 'J',
        currencyCode => 'T1',
        units        => 'N',
        price        => 'T'
    };
}

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 =~ /^Streaming - (?:Family|Student|Sponsor$)$/i
        || $type =~ /^Streaming - (?:Annual|Hard Bundle|HiResHard Bundle)(?:\(VAS\))?$/i
        || $type =~ /^Streaming - HiRes(?:Monthly|Annual|Family)$/i
        || $type =~ /^Sponsor$/i
        || $type =~ /^UtaPass (?:Basic|MyUta Plus|SmartPass|Ondemand)$/i
        || $type =~ /^HMV Music - Monthly$/i ) {
        return RPS::File::Sale::FORMAT_STREAM;
    } elsif ( $type =~ /^download$/i ) {
        return RPS::File::Sale::FORMAT_DOWNLOAD;
    }

    $self->handleError( "Unknown service: '$type'", RPS::DB::Item::SaleImportError::kErrorFormatType );
}

sub _mapFaceServiceID   {}
sub _mapFaceCountryCode {}
sub _mapFaceProductType {}
sub _mapFaceFormatType  { 'formatType' }
sub _mapFaceMediaType   {}


1;
