package RPS::Import::PlayNetwork2015;

use strict;

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

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

use Data::Dumper;
use Date::Calc qw(Days_in_Month Decode_Month);

sub _fieldMap {
    {
        # header
        dateBegin => 'A3',
        dateEnd   => 'A3',

        # detail
        artistName => 'D',
        albumName  => 'C',
        isrc       => 'B',
        trackName  => 'A',
        units      => 'E',
        price      => 'F',
    };
}

sub _headerIdentifier { ( isrc => 'ISRC' ) }

sub countryCode  { 'US' }
sub currencyCode { 'USD' }
sub productType  { RPS::File::Sale::TYPE_TRACK }
sub formatType   { RPS::File::Sale::FORMAT_STREAM }
sub mediaType    { RPS::DB::Item::MediaType::kMediaTypeAudio }

sub _getDateBegin {
    my $self = shift;
    my $date = $self->_getByFieldName('dateBegin') || return;

    if ( $date && $date =~ /^(\d{1,2})\/(\d{1,2})\/(\d{4})/ ) {
        return sprintf( "%04d-%02d-%02d", $3, $1, $2 );
    }
}

sub _getDateEnd {
    my $self = shift;
    my $date = $self->_getByFieldName('dateEnd') || return;

    if ( $date && $date =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})$/ ) {
        return sprintf( "%04d-%02d-%02d", $3, $1, $2 );
    }
}

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