#!/usr/bin/perl
use strict;
use warnings;

package API::PageTitle;

use MIME::Base64;
use MIME::Entity;
use MIME::Lite;
use WebService::Rackspace::CloudFiles;

use SOAP::Lite ();
use base 'SOAP::Server::Parameters';

our $Config;
BEGIN{
	use API::Config;
	$Config = $API::Config::Config;
}
use lib ($Config->{Website_libs});
use ECS::SQL;
use ECS::dbConfig;

my $DBH = ECS::SQL::connect($ECS::dbConfig::db{'tms'});

sub update {
	
	my $ref = shift;
	my $input = shift;
		
	my $result = {
		'success'	=> 1,
		'error'		=> undef,
		'update_DB'	=> $Config->{update_DB}
	};
	# IF we want to write to DB (Determined by API::Config)
	# --------------------------------------------------
	if ($Config->{update_DB}){
		if(!ECS::SQL::update({
	         DBH => $DBH,
	         table => 'product',
	         key => 'productID',
	         columns => [qw(title)],
	         hash => {productID => $input->{productID}, title => $input->{title}}		
	     })){
				
	     		$result->{success} = 0;
				$result->{error} = "Unable to update PageTitle API.";
	     }
	}
    return $result;
}


sub delete {

	my $ref = shift;
	my $input = shift;
		
	my $productID = $input->{'removeTitle'};
	
	my $result = {
		'success'	=> 1,
		'error'		=> undef,
		'update_DB'	=> $Config->{update_DB}
	};
	
	my $sql = "UPDATE product SET title = null WHERE productID = $productID";
	my $rd = ECS::SQL::query({DBH => $DBH, sql => $sql });
	
	if ($Config->{update_DB}){
		if (!$rd){
				$result->{success} = 0;
				$result->{error} = "Unable to remove PageTitle.";
	     }
	}

	return $result;
}

1;
