package RPS::Import::ZeroInch::v1;

use strict;

use lib '/app/tools/common/lib';
use Common::Date;
use Common::Country;

use lib '/app/tools/rps/lib';
use base 'RPS::Import::Importer';

use Data::Dumper;

sub _headerIdentifier { ( upc => 'EAN' ) }

sub _fieldMap {
    {
        dateBegin        => 'A',
        labelName        => 'G',
        countryCode      => 'L',
        artistName       => 'E',
        upc              => 'C',
        albumName        => 'F',
        isrc             => 'D',
        trackName        => 'F',
        price            => 'K',
    }
}

sub formatType  { return RPS::File::Sale::FORMAT_DOWNLOAD; }

sub currencyCode  { return "EUR"; }

sub units { return 1; }

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

sub productType {
    my $self = shift;
    if( $self->upc )
    {
        return RPS::File::Sale::TYPE_ALBUM;
    }
    elsif( $self->isrc )
    {
        return RPS::File::Sale::TYPE_TRACK;
    }
}

sub upc {
    my $self = shift;
    my $upc  = $self->_getByFieldName('upc') || return;
    undef $upc if ( $upc eq "-" );
    return $upc;
}

sub isrc {
    my $self = shift;
    my $isrc = $self->_getByFieldName('isrc') || return;
    undef $isrc if ( $isrc eq "-" );
    return $isrc;
}

sub albumName {
    my $self  = shift;
    my $title = $self->_getByFieldName('albumName') || return;
    my $upc   = $self->_getByFieldName('upc');

    if( $upc && $upc ne '-')
    {
        return $title;
    }
}

sub trackName {
    my $self  = shift;
    my $title = $self->_getByFieldName('trackName') || return;
    my $isrc  = $self->_getByFieldName('isrc');

    if( $isrc && $isrc ne '-')
    {
        return $title;
    }
}

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