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

NSString * const BanUserRequest_KEY_USER_ID = @"u";
NSString * const BanUserRequest_KEY_MESSAGE = @"m";
NSString * const BanUserRequest_KEY_DELAY = @"d";
NSString * const BanUserRequest_KEY_BAN_MODE = @"b";


@implementation BanUserRequest


-(id)initWithUserId:(NSInteger)userId message:(NSString *)message banMode:(NSInteger)banMode delaySeconds:(NSInteger)delaySeconds {
	
	if ((self = [super initWithId:BaseRequest_BanUser])) {
		_userId = userId;
		_message = message;
		_banMode = banMode;
		_delay = delaySeconds;
	}
	
	return self;
}

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

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


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


-(void)execute:(SmartFox2XClient *)sfs{
	
	[_sfso putInt:BanUserRequest_KEY_USER_ID value:_userId];
	[_sfso putInt:BanUserRequest_KEY_DELAY value:_delay];
	[_sfso putInt:BanUserRequest_KEY_BAN_MODE value:_banMode];
	
	if (_message != nil && [_message length] > 0) {
		[_sfso putUtfString:BanUserRequest_KEY_MESSAGE value:_message];
	}
	
}


@end
