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

use lib '/app/tools/rps/lib';

use base 'RSApache::Command::XMLCommand';

use lib '/app/tools/common/lib';
use RSApache::Response::Raw;

use lib '/app/tools/rps/lib';
use RPS::Product::ProductDistribution;

use lib '/app/tools/appuser/lib';
use AppUser::DB::Item::AccessLevel;

sub cmd  { return 'toggle_distribution'; }
sub area { return 'product'; }

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

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

	my $value = $self->getParam( 'value' );
	
	my $service_id = $self->getParam( 'service_id' );
	my $product_id = $self->getParam( 'product_id' );
	
	my $prod_dist = new RPS::Product::ProductDistribution( service_id => $service_id,
														   product_id => $product_id );
	
	my $result = $prod_dist && $prod_dist->toggleStagedDistribution( $value ) ? "OK" : "ERROR";
	
    $response = RSApache::Response::Raw->new( $result );

    return $response;
}


1;
