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


NSString * const GoOnlineRequest_KEY_ONLINE = @"o";
NSString * const GoOnlineRequest_KEY_BUDDY_NAME = @"bn";
NSString * const GoOnlineRequest_KEY_BUDDY_ID = @"bi";

@implementation GoOnlineRequest


-(id)initWithOnline:(BOOL)online {
	if ((self = [super initWithId:BaseRequest_GoOnline])) {
		_online = online;
	}
	
	return self;
}

+(id)requestWithOnline:(BOOL)online {
	GoOnlineRequest *req = [[GoOnlineRequest alloc] initWithOnline:online];
	return req;
}

-(void)validate:(SmartFox2XClient *)sfs {
	
	NSMutableArray *errors = [NSMutableArray array];
	
	if (![sfs.buddyManager isInited]) {
		[errors addObject:@"BuddyList is not inited. Please send an InitBuddyRequest first."];
	}
		
	if ([errors count] > 0) {
		@throw [SFSValidationException validationExceptionWithReason:@"GoOnline request error" errors:errors];
	}
}


-(void)execute:(SmartFox2XClient *)sfs{
	
	[sfs.buddyManager setMyOnlineState:_online];
	
	[_sfso putBool:GoOnlineRequest_KEY_ONLINE value:_online];
}


@end
