package RPS::Import::7Digital::v15;

use strict;

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

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

sub _fieldMap {
    {
        dateBegin    => 'A',
        labelName    => 'L',
        formatType   => 'C',
        upc          => 'I',
        artistName   => 'G',
        albumName    => 'K',
        isrc         => 'F',
        trackName    => 'H',
        units        => 'M',
        price        => 'N',
        countryCode  => 'B',
        currencyCode => 'O',
    };
}

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

sub saleDates {
    my $self = shift;
    my $dt   = $self->_getByFieldName('dateBegin');

    my $type = "eur";
    $type = "iso" if ($dt =~ /^\d{4}-/);

    return $self->_getDates( date_begin => $dt, type => $type );
}

sub productType { RPS::File::Sale::TYPE_TRACK; }

sub formatType {
    my $self = shift;
    my $type = $self->_getByFieldName('formatType');
    if ( $type =~ /^(premium|trial)-unlimited-streaming$/i ) {
        return RPS::File::Sale::FORMAT_STREAM;
    }
    $self->fail("Unable to get format type from '$type'");
}

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

sub free {
    my $self  = shift;
    my $type  = $self->_getByFieldName('formatType');
    my $price = $self->_getByFieldName('price');
    return 1 if ( $type =~ /^trial-unlimited-streaming$/i && 0 == $price );
}

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