#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package Support::LoadHistory::Command::Detail;
use strict;
use warnings;

use lib '/app/tools/support/lib';
use base 'Support::Command';
use Support::LoadHistory::DailyLoadGraph;

use lib '/app/tools/common/lib';
use RSApache::Response::Direct;

use lib '/app/tools/support/lib';

sub cmd  { return 'detail' }
sub area { return 'load' }

use constant kImagesPath => '/app/data/load_logs_images';

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

    my $response = $self->SUPER::execute();
    return $response if $response;

    my $graphObj   = Support::LoadHistory::DailyLoadGraph->new( file => $self->getParam('file') );
    my $tmpFile    = $graphObj->draw(kImagesPath);
    my $pathToFile = kImagesPath . "/$tmpFile";

    open( FD, "$pathToFile" ) or die "ERROR - cannot open file $pathToFile for reading";
    $response = RSApache::Response::Direct->new( *FD, 'image/png' );

    return $response;
}

1;
