#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package RPS::Import::Bleep::v4;

use strict;

use lib '/app/tools/rps/lib';
use RPS::DB::Item::Client;

use lib '/app/tools/common/lib';
use Common::Consts;
use Common::Assert;
use Common::Log;

use lib '/app/tools/data_classes/lib';

use lib '/app/tools/rps/lib';
use RPS::Import::SaleRec;
use RPS::DB::Item::MediaType;
use RPS::File::Sale;

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

sub _fieldMap {
    {
        labelName       => 'C',
        countryCode     => 'O',
        type            => 'G',
        artistName      => 'I',
        albumName       => 'J',
        trackName       => 'K',
        upc             => 'M',
        isrc            => 'N',
        units           => 'T',
        price           => 29,
    }
}

sub _unverifiedFieldMap {
    {
        month   => 'A',
        year    => 'B',
        format  => 'H',
    }
}

sub trackName {
    my $self = shift;
    my $type = $self->_getByFieldName('type');
    my $trackName;
    if ( $type =~ m/track/i ) {
        $trackName = $self->_getByFieldName('trackName');
    }
    return $trackName;
}

sub currencyCode { 'GBP' }

sub _headerIdentifier { ( type => 'ProductType' ) }

sub _productTypes {
    {
        'full release' =>
        {
           productType => RPS::File::Sale::TYPE_ALBUM,
           formatType => RPS::File::Sale::FORMAT_DOWNLOAD,
           mediaType => RPS::DB::Item::MediaType::kMediaTypeAudio,
        },
        'release' =>
        {
           productType => RPS::File::Sale::TYPE_ALBUM,
           formatType => RPS::File::Sale::FORMAT_DOWNLOAD,
           mediaType => RPS::DB::Item::MediaType::kMediaTypeAudio,
        },
        'track' =>
        {
           productType => RPS::File::Sale::TYPE_TRACK,
           formatType => RPS::File::Sale::FORMAT_DOWNLOAD,
           mediaType => RPS::DB::Item::MediaType::kMediaTypeAudio,
        },
    }
}

sub formatType {
    my $self = shift;
    my $format = lc($self->_getByFieldName('format')) || return;

    if( $format eq 'mp3' ) {
        return RPS::File::Sale::FORMAT_DOWNLOAD,
    } elsif( $format eq 'flac' ) {
        return RPS::File::Sale::FORMAT_DOWNLOADPREMIUM,
    } elsif( $format eq 'wav' ) {
        return RPS::File::Sale::FORMAT_DOWNLOADPREMIUM,
    } else {
        $self->fail( "Unable to determine format from '$format'" );
    }
}
sub saleDates {
    my $self = shift;
    my $month = $self->_getByFieldName('month');
    my $year  = $self->_getByFieldName('year');
    my $d = sprintf("%04d-%02d-%02d", $year, $month, 1);
    return $self->_getDates( date_begin => $d );
}

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