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

use lib '/app/tools/rps/lib';
use RPS::Catalog::AlbumContract;
use RPS::ArtistContract::Command::Show;
use RPS::ArtistContract::Command::Search;

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

use RPS::Command;
use base 'RPS::Command';

sub cmd  { return 'cc'; }
sub area { return 'contract'; }

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

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

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

    my $contractID      = $self->getParam('ArtistContractID');
    my $albumContractID = $self->getParam('AlbumContractID');
    my $form;

    if ( !$albumContractID ) {
        my $command = RPS::ArtistContract::Command::Search->new();
    }

    # Get the advance object, then flip it's cross-colateralized value.
    #
    my $albumContract = RPS::Catalog::AlbumContract->new( albumContractID => $albumContractID );
    $albumContract->CrossCollateralized( $albumContract->CrossCollateralized() ? 0 : 1 );
    $albumContract->save();

    my $successMessage = RPS::Message->new( type => "success", code => Common::FormObject::kSuccessFormSubmit );
    my $command = RPS::ArtistContract::Command::Show->new( ArtistContractID => $contractID, msg => $successMessage->toString );
    return RSApache::Response::Redirect->new( $command->getRedirect() );
}

1;

