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

NSString * const InvitationReplyRequest_KEY_INVITATION_ID = @"i";
NSString * const InvitationReplyRequest_KEY_INVITATION_REPLY = @"r";
NSString * const InvitationReplyRequest_KEY_INVITATION_PARAMS = @"p";


@implementation InvitationReplyRequest


@synthesize invitation = _invitation;
@synthesize reply = _reply;
@synthesize params = _params;


-(id)initWithInvitation:(id <Invitation>)invitation invitationReply:(NSInteger)invitationReply params:(id <ISFSObject>)params {
	if ((self = [super initWithId:BaseRequest_InvitationReply])) {
		
		self.invitation = invitation;
		_reply = invitationReply;
		self.params = params;
	}
	
	return self;
	
}

+(id)requestWithInvitation:(id <Invitation>)invitation invitationReply:(NSInteger)invitationReply params:(id <ISFSObject>)params {
	InvitationReplyRequest *req = [[InvitationReplyRequest alloc] initWithInvitation:invitation invitationReply:invitationReply params:params];
	return req;
}

-(void)validate:(SmartFox2XClient *)sfs {
	
	NSMutableArray *errors = [NSMutableArray array];
	
	if (_invitation == nil) {
		[errors addObject:@"Missing invitation object"];
	}
	
	if ([errors count] > 0) {
		@throw [SFSValidationException validationExceptionWithReason:@"InvitationReply request error" errors:errors];
	}
}


-(void)execute:(SmartFox2XClient *)sfs{

	[_sfso putInt:InvitationReplyRequest_KEY_INVITATION_ID value:[_invitation id]];
	[_sfso putByte:InvitationReplyRequest_KEY_INVITATION_REPLY value:_reply];
	
	if (_params != nil) {
		[_sfso putSFSObject:InvitationReplyRequest_KEY_INVITATION_PARAMS value:_params];
	}
}



@end
