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

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

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

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

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

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

    # Give any inherited methods the first crack at this.
    # (This checks for login and basic access permissions).
    #
    my $response = $self->SUPER::execute();
    return $response if $response;

    my $periodType = lc( $self->getParam("period_type") || 'q' );
    my $periodParam = $self->getParam("period");
    my $endPeriod   = $self->getParam("end_period");

    #my $imprintID = $self->getParam("imprint") || $self->_getUser()->ImprintID() || undef;
    my $imprintID   = $self->getParam("imprint") || undef;
    my $countryCode = $self->getParam("country");
    my $productID   = $self->getParam("product");

    $self->{xml}{Report} = BookPub::Analytics::TrackDetailReport->new(
        periodType  => $periodType,
        periodParam => $periodParam,
        endPeriodParam => $endPeriod,
        imprintID   => $imprintID,
        countryCode => $countryCode,
        productID   => $productID,
        commandObj  => $self,
    );

    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );
    return $response;
}

1;
