//
//  KickUserRequest.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 "KickUserRequest.h"
#import "SmartFox2XClient.h"

NSString * const KickUserRequest_KEY_USER_ID = @"u";
NSString * const KickUserRequest_KEY_MESSAGE = @"m";
NSString * const KickUserRequest_KEY_DELAY = @"d";


@implementation KickUserRequest



-(id)initWithUserId:(NSInteger)userId message:(NSString *)message delaySeconds:(NSInteger)delaySeconds {

	

	if ((self = [super initWithId:BaseRequest_KickUser])) {
		
		_userId = userId;
		_message = message;
		_delay = (delaySeconds < 0) ? 0 : delaySeconds;
        
	}
	
    //if (_delay < 0) {
    //    _delay = 0;
    //}
	
	return self;

}

+(id)requestWithUserId:(NSInteger)userId message:(NSString *)message delaySeconds:(NSInteger)delaySeconds {
	KickUserRequest *req = [[KickUserRequest alloc] initWithUserId:userId message:message delaySeconds:delaySeconds];
	return req;
}

+(id)requestWithUserId:(NSInteger)userId {
	KickUserRequest *req = [[KickUserRequest alloc] initWithUserId:userId message:nil delaySeconds:5];
	return req;
}

-(void)validate:(SmartFox2XClient *)sfs {
	
	NSMutableArray *errors = [NSMutableArray array];
		
	if ([errors count] > 0) {
		@throw [SFSValidationException validationExceptionWithReason:@"KickUser request error" errors:errors];
	}
}


-(void)execute:(SmartFox2XClient *)sfs{
	
	[_sfso putInt:KickUserRequest_KEY_USER_ID value:_userId];
	[_sfso putInt:KickUserRequest_KEY_DELAY value:_delay];
	
	if (_message != nil && [_message length] > 0) {
		[_sfso putUtfString:KickUserRequest_KEY_MESSAGE value:_message];
	}
}


@end
