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

NSString * const ChangeRoomCapacityRequest_KEY_ROOM = @"r";
NSString * const ChangeRoomCapacityRequest_KEY_USER_SIZE = @"u";
NSString * const ChangeRoomCapacityRequest_KEY_SPEC_SIZE = @"s";

@implementation ChangeRoomCapacityRequest



-(id)initWithRoom:(id<Room>)room newMaxUsers:(NSInteger)newMaxUsers newMaxSpect:(NSInteger)newMaxSpect {
	
	if ((self = [super initWithId:BaseRequest_ChangeRoomCapacity])) {
		_room = room;
		_newMaxSpect = newMaxSpect;
		_newMaxUsers = newMaxUsers;
	}
	
	return self;
}

+(id)requestWithRoom:(id<Room>)room newMaxUsers:(NSInteger)newMaxUsers newMaxSpect:(NSInteger)newMaxSpect {
	ChangeRoomCapacityRequest *req = [[ChangeRoomCapacityRequest alloc] initWithRoom:room newMaxUsers:newMaxUsers newMaxSpect:newMaxSpect];
	return req;
}


-(void)validate:(SmartFox2XClient *)sfs {
	
	NSMutableArray *errors = [NSMutableArray array];
	
	if(_room == nil) {
		[errors addObject:@"Provided room is null"];
	}
	
	if ([errors count] > 0) {
		@throw [SFSValidationException validationExceptionWithReason:@"ChangeRoomCapacity request error" errors:errors];
	}
}


-(void)execute:(SmartFox2XClient *)sfs{
	
	[_sfso putInt:ChangeRoomCapacityRequest_KEY_ROOM value:[_room id]];
	[_sfso putInt:ChangeRoomCapacityRequest_KEY_USER_SIZE value:_newMaxUsers];
	[_sfso putInt:ChangeRoomCapacityRequest_KEY_SPEC_SIZE value:_newMaxSpect];
	
}


@end
