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

package RPS::Import::Nimbit::v1;

use strict;

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

sub _fieldMap {
    {
        # detail section of each sheet
        #
        albumName     => 'H',
        configuration => 'G',
        dateBegin     => 'E',
        upc           => 'AC',
        sales         => 'I',
        salesRevenue  => 'M',
        totalRevenue  => 'M',
    };
}

sub _headerIdentifier { ( albumName => 'Product' ) }

sub currencyCode { 'USD'; }
sub countryCode  { 'US'; }
sub channel      { RPS::File::Sale::CHANNEL_RETAIL; }
sub priceLevel   { RPS::File::Sale::PLEVEL_UNKNOWN; }
sub physical     { 1 }

sub productType {
    my $self   = shift;
    my $config = $self->_getByFieldName('configuration');

    if ( $config =~ /^cd$/i ) {
        return RPS::File::Sale::TYPE_CD;
    }
    $self->fail("Unable to determine config from format($config)");
}

sub _isValidSaleRecord {
    my $self = shift;

    # The line is valid if it has sales or returns, and has an album title
    #
    return ( ( $self->sales != 0 || $self->returns != 0 ) && $self->albumName );
}

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