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

use strict;

use Date::Calc qw(Days_in_Month Decode_Month);

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

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

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

sub _fieldMap {
    my $self = shift;
    my %field_map = (
        2 => {
            dateBegin     => 'I',
            dateEnd       => 'I',
            countryCode   => 'J',
            artistName    => 'G',
            upc           => 'F',
            isrc          => 'C',
            trackName     => 'H',
            units         => 'O',
            price         => 'P',
            mediaType     => 'L',
        },
        3 => {
            dateBegin     => 'I',
            dateEnd       => 'I',
            countryCode   => 'J',
            artistName    => 'G',
            upc           => 'F',
            isrc          => 'C',
            trackName     => 'H',
            units         => 'P',
            price         => 'R',
            mediaType     => 'L',
        },
    );
    return $field_map{$self->_version};
}

sub _headerIdentifier { ( trackName => 'Title' ) }

sub currencyCode { 'USD' }

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

sub formatType { RPS::File::Sale::FORMAT_STREAM }

sub mediaType {
    my $self = shift;
    my $type = $self->_getByFieldName('mediaType');
    if( $type =~ /^audio(?:-visual)?$/i )
    {
        return RPS::DB::Item::MediaType::kMediaTypeAudio;
    }
    elsif( $type =~ /^visual$/i )
    {
        return RPS::DB::Item::MediaType::kMediaTypeVideo;
    }
    $self->fail("Unknown media type $type");
}

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