//
//  ChangeRoomPasswordStateRequest.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 "ChangeRoomPasswordStateRequest.h"

NSString * const ChangeRoomPasswordStateRequest_KEY_ROOM = @"r";
NSString * const ChangeRoomPasswordStateRequest_KEY_PASS = @"p";

@implementation ChangeRoomPasswordStateRequest


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

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

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


-(void)execute:(SmartFox2XClient *)sfs{
	
	[_sfso putInt:ChangeRoomPasswordStateRequest_KEY_ROOM value:[_room id]];
	[_sfso putUtfString:ChangeRoomPasswordStateRequest_KEY_PASS value:_newPass];
	
	
}

@end
