//
//  BaseRequest.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 "BaseRequest.h"
#import "SFSObject.h"
#import "Message.h"

NSInteger const BaseRequest_Handshake = 0;
NSInteger const BaseRequest_Login = 1;
NSInteger const BaseRequest_Logout = 2;
NSInteger const BaseRequest_GetRoomList = 3;
NSInteger const BaseRequest_JoinRoom = 4;
NSInteger const BaseRequest_AutoJoin = 5;
NSInteger const BaseRequest_CreateRoom = 6;
NSInteger const BaseRequest_GenericMessage = 7;
NSInteger const BaseRequest_ChangeRoomName = 8;
NSInteger const BaseRequest_ChangeRoomPassword = 9;
NSInteger const BaseRequest_ObjectMessage = 10;
NSInteger const BaseRequest_SetRoomVariables = 11;
NSInteger const BaseRequest_SetUserVariables = 12;
NSInteger const BaseRequest_CallExtension = 13;
NSInteger const BaseRequest_LeaveRoom = 14;
NSInteger const BaseRequest_SubscribeRoomGroup = 15;
NSInteger const BaseRequest_UnsubscribeRoomGroup = 16;
NSInteger const BaseRequest_SpectatorToPlayer = 17;
NSInteger const BaseRequest_PlayerToSpectator = 18;
NSInteger const BaseRequest_ChangeRoomCapacity = 19;
NSInteger const BaseRequest_PublicMessage = 20;
NSInteger const BaseRequest_PrivateMessage = 21;
NSInteger const BaseRequest_ModeratorMessage = 22;
NSInteger const BaseRequest_AdminMessage = 23;
NSInteger const BaseRequest_KickUser = 24;
NSInteger const BaseRequest_BanUser = 25;
NSInteger const BaseRequest_ManualDisconnection = 26;
NSInteger const BaseRequest_FindRooms = 27;
NSInteger const BaseRequest_FindUsers = 28;
NSInteger const BaseRequest_PingPong = 29;
NSInteger const BaseRequest_SetUserPosition = 30;
NSInteger const BaseRequest_QuickJoinOrCreateRoom = 31;

NSInteger const BaseRequest_InitBuddyList = 200;
NSInteger const BaseRequest_AddBuddy = 201;
NSInteger const BaseRequest_BlockBuddy = 202;
NSInteger const BaseRequest_RemoveBuddy = 203;
NSInteger const BaseRequest_SetBuddyVariables = 204;
NSInteger const BaseRequest_GoOnline = 205;


NSInteger const BaseRequest_InviteUser = 300;
NSInteger const BaseRequest_InvitationReply = 301;
NSInteger const BaseRequest_CreateSFSGame = 302;
NSInteger const BaseRequest_QuickJoinGame = 303;
NSInteger const BaseRequest_JoinRoomInvite = 304;

NSString * const BaseRequest_KEY_ERROR_CODE = @"ec";
NSString * const BaseRequest_KEY_ERROR_PARAMS = @"ep";

@implementation BaseRequest

@synthesize sfso = _sfso;
@synthesize isUDP = _isUDP;


-(id)initWithId:(NSInteger)id_
{
	if ((self = [super init])) {
		self.sfso = [SFSObject newInstance];
        self.isUDP = NO;
		_id = id_;
		_targetController = 0;
		_isEncrypted = NO;
	}
	
	return self;
}

-(NSInteger)getId {
	return _id;
}

-(void)setId:(NSInteger)id_ {
	_id = id_;
}


-(void)validate:(SmartFox2XClient *)sfs {
	// Override in child class
	// Throws exception if invalid request.
}


-(void)execute:(SmartFox2XClient *)sfs{
	// Override in child class
}


-(NSInteger)getTargetController {
	return _targetController;
}
-(void)setTargetController:(NSInteger)target {
	_targetController = target;
}


-(BOOL)getIsEncrypted {
	return _isEncrypted;
}
-(void)setIsEncrypted:(BOOL)flag {
	_isEncrypted = flag;
}


-(id<IMessage>)getMessage {
	id<IMessage> message = [Message alloc];
    
	[message setId:_id];
	[message setIsEncrypted:_isEncrypted];
	[message setTargetController:_targetController];
	[message setContent:_sfso];
    [message setIsUDP:_isUDP];
	
	return message;
	
}







@end
