//
//  ChangeRoomNameRequest.m
//  SFS2X
//
//  Original development by Infosfer Game Technologies Ltd. | http://www.infosfer.com.
//
//  Maintained and developed by A51 Integrated.
//  Copyright 2012 A51 Integrated | http://a51integrated.com. All rights reserved.
//
#import "ChangeRoomNameRequest.h"

NSString * const ChangeRoomNameRequest_KEY_ROOM = @"r";
NSString * const ChangeRoomNameRequest_KEY_NAME = @"n";


@implementation ChangeRoomNameRequest


-(id)initWithRoom:(id<Room>)room newName:(NSString *)newName {
	
	if ((self = [super initWithId:BaseRequest_ChangeRoomName])) {
		_room = room;
		_newName = newName;
	}
	return self;
	
}

+(id)requestWithRoom:(id<Room>)room newName:(NSString *)newName
{
	ChangeRoomNameRequest *req = [[ChangeRoomNameRequest alloc] initWithRoom:room newName:newName];
	return req;
}

-(void)validate:(SmartFox2XClient *)sfs
{	
	NSMutableArray *errors = [NSMutableArray array];
	
	if(_room == nil) {
		[errors addObject:@"Provided room is null"];
	}
	
	if(_newName == nil || [_newName length] == 0) {
		[errors addObject:@"Invalid new room name. It must be a non-null and non-empty string."];
	}
	
	if ([errors count] > 0) {
		@throw [SFSValidationException validationExceptionWithReason:@"ChangeRoomName request error" errors:errors];
	}
}


-(void)execute:(SmartFox2XClient *)sfs{
	
	[_sfso putInt:ChangeRoomNameRequest_KEY_ROOM value:[_room id]];
	[_sfso putUtfString:ChangeRoomNameRequest_KEY_NAME value:_newName];
	
	
}



@end
