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

package RPS::LabelRoyalty::Fast::Static::Services;

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

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;

use base 'RPS::LabelRoyalty::Fast::Static';


use constant kServiceID             => 0;
use constant kServiceName           => 1;


sub FileName { 'services' }
sub CacheQueryTableList { "'service'"};


sub _Create
{
    my ($class, $filename, $payorID) = @_;


    # JPK - Not going to bother with a BerkeleyDB file for this data, since it's really rather small.
    # Just going to stuff it all into a single hash which we'll eval (or rather use 'do') to load back in.
    #

    my %hash;

    my $dbo = Common::RSApp::GetClientDB();

    my $sql = "SELECT service_id, service_name FROM service";

    # !!! The data structure handles dups, so no need to sort the query result.

    my $sth = $dbo->DoCmd($sql);

    while (my $row = $sth->fetchrow_arrayref())
    {
        # Note that because this is a tied array, backed by a DB_BTREE with R_DUP enabled, we can store
        # multiple values in a single key.
        #
        $hash{ $row->[kServiceID] } = $row->[kServiceName];
    }

    $Data::Dumper::Terse = 1;
    open OUTFH, "> $filename" or die "ERROR: $!";
    print OUTFH Dumper(\%hash);
    close OUTFH;

}


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

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

    my $data = do $filename or die "ERROR: $!";
    return $data;

}



1;
