#------------------------------------------------------------
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::Analytics::Command::SnapshotServiceDetail;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use RSApache::Response::XSLTDownload;
use RSApache::Response::DownloadStream;
use Common::Assert;
use Common::Log;

use lib '/app/tools/bookpub/lib';
use BookPub::Analytics::SnapshotServiceDetail;
use base 'BookPub::Command';

sub cmd  { return "snapshot_main"; }
sub area { return "analytics"; }

use constant kTemplate => '/app/tools/bookpub/templates/analytics.xsl';

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

    my $excel = BookPub::Analytics::SnapshotServiceDetail->new(
        periodType => lc( $self->getParam('period_type') || 'q' ),
        periodParam => $self->getParam('period'),
        endPeriodParam => $self->getParam("end_period"),
        imprintID   => $self->getParam('imprint') || undef,
        publisherID => $self->getParam('publisher') || undef,
        serviceID   => $self->getParam('service'),
        countryCode => $self->getParam('country'),
        commandObj  => $self,
    );

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

    $response =
      RSApache::Response::DownloadStream->new( $excel->{data}, "application/octet-stream", "Analytics_Snapshot-Service_Detail.xls" );

    return $response;
}

1;
