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

package RPS::ArtistRoyalty::Fast::Mapped::MissedSales;

use strict;
use Data::Dumper;
use File::Path;
use IO::File;

use lib '/app/tools/common/lib';
use lib '/app/tools/rps/lib';
use lib '/app/tools/raptor/lib';
use Common::RSApp;

use Data::Dumper;
use DB_File;

use Common::Log;



# Data column indexes
#
use constant kProductID           => 0;
use constant kArtistContractID    => 1;
use constant kReasonCode          => 2;
use constant kDetails             => 3;
use constant kUnits               => 4;


# 'reason' codes
#
use constant kNoContracts         => 1;
use constant kNoPrice             => 2;
use constant kNoIncomeSource      => 3;
use constant kNoDefaultTerm       => 4;

sub FileName { 'missed_sales' }



sub Reason
{
    my ($code) = @_;

    return 'No contracts' if kNoContracts == $code;
    return 'No product price' if kNoPrice == $code;
    return 'No income source' if kNoIncomeSource == $code;
    return 'No matching term' if kNoDefaultTerm == $code;
#    return $gReasons{$code} || 'unknown';
}

sub _new
{  
    my ($class, $dataPath) = @_;

    my $self = bless {}, $class;
    return $self->_init($dataPath);
}

sub _init
{
    my ($self, $dataPath) = @_;

    $self->{FD} = IO::File->new("< $dataPath") or die "ERROR : Unable to open $dataPath for reading: $!";

    return $self;
}

sub nextLine
{
    my ($self) = @_;

    my $fd = $self->{FD};
    my $line = <$fd>;
    return undef unless $line;

    chomp $line;
    my @data = split("\t", $line);
    return \@data;
}

sub GetMissedSales
{
    my ($class, $dataPath) = @_;

    my $filename = "$dataPath/" . $class->FileName() . '.sorted';

    return $class->_new($filename);
}




1;

