#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2014 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------
package RPS::Import::iHeartRadio;

use strict;

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

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

sub _fieldMap {{
    labelName     => 'G',
    artistName    => 'C',
    isrc          => 'E',
    trackName     => 'D',
    units         => 'H',
}}

sub _noHeader { 1 }

sub countryCode { 'US' }

sub currencyCode { 'USD' }

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

sub formatType { RPS::File::Sale::FORMAT_PERFORMANCE; }

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

sub _cleanField {
    my $s = shift;
    $s =~ s/^\^//; # strip leading/trailing carets
    $s =~ s/\^$//;
    return $s;
}

sub labelName {
    return _cleanField( shift->_getByFieldName('labelName'));
}

sub trackName {
    return _cleanField( shift->_getByFieldName('trackName'));
}

sub artistName {
    return _cleanField( shift->_getByFieldName('artistName'));
}

sub isrc {
    return _cleanField( shift->_getByFieldName('isrc'));
}

sub units {
    my $u  = shift->_getByFieldName('units');
    $u =~ s/\.00//;
    return $u;
}

sub saleDates {
    my $self = shift;
    if(!exists $self->{_startDate})
    {
        if($self->filename =~ /(\d{8})\.txt/) # YYYYMMDD
        {
            ($self->{_startDate}, $self->{_endDate}) = $self->_getDates(date_begin => $1);
        }
    }

    return ($self->{_startDate}, $self->{_endDate});
}

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