#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::Catalog::Command::ShowBook;
use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use BookPub::Command;
use BookPub::Catalog::Book::FullDisplay;
use BookPub::Catalog::ChapterList;
use BookPub::Catalog::BookProductListBatch;
use BookPub::Catalog::GroupedBookProducts;
use BookPub::Price::PriceTypeList;
use BookPub::Catalog::ImprintList;
use Common::CommandLog;
use Common::Assert;

use base 'BookPub::Command';

sub cmd      { return 'show_book'; }
sub area     { return 'catalog'; }
sub pageName { return 'View Book'; }

use constant kTemplate => "/app/tools/bookpub/templates/catalog/show_book.xsl";

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

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

    my $bookID = $self->getParam('BookID');
    $self->{xml}{Book} = BookPub::Catalog::Book::FullDisplay->new( bookID => $bookID );
    $self->{xml}{PriceTypes} = BookPub::Price::PriceTypeList->new();

    my $oMasterBookProductList = BookPub::Catalog::BookProductListBatch->new( bookID => $bookID );
    $self->{xml}{BookProductGroups} = BookPub::Catalog::GroupedBookProducts->new( bookProductList => $oMasterBookProductList );
    $self->{xml}{ImprintList} = BookPub::Catalog::ImprintList->new();

    Common::CommandLog::Log( $self, $bookID );

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

1;
