#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Catalog::Command::Detach;
use strict;
use warnings;

use lib '/app/tools/rps/lib';
use RPS::Catalog::ContractForm;
use RPS::Catalog::Command::Show;
use RPS::Command;

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

use base 'RPS::Command';

sub cmd  { return 'detach'; }
sub area { return 'catalog'; }

use constant kTemplate => "/app/tools/rps/templates/catalog/index.xsl";

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

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

    my $albumContractID = $self->getParam('AlbumContractID');
    assert($albumContractID);

    # Instantiate an AlbumContract object, and we'll see how that goes.
    #
    my $obj = RPS::Catalog::AlbumContract->new( albumContractID => $albumContractID );

    my $message;
    if ( $obj->delete() ) {
        $message = RPS::Message->new( type => "success", code => Common::FormObject::kSuccessFormSubmit );
    } else {
        $message = RPS::Message->new( type => "error", code => Common::FormObject::kErrFormSubmit );
    }

    my %showParams = (
        AlbumID => $obj->AlbumID(),
        msg     => $message->toString(),
        tab     => RPS::Catalog::Command::Show::kTabContracts,
    );
    my $command = RPS::Catalog::Command::Show->new(%showParams);
    return RSApache::Response::Redirect->new( $command->getRedirect() );
}

1;
