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


@implementation SFSErrorCodes

//static NSMutableArray *_errorsByCode = nil;
static NSMutableDictionary* _errorsByCode = nil;

+(void)initialize
{
    _errorsByCode =  [NSMutableDictionary
                      dictionaryWithDictionary:@{
                         @0:@"Client API version is obsolete: {0}, Required version: {1}",    // 0
                         @1:@"Requested Zone: {0} does not exist.",
                         @2:@"Username: {0} is not recognized",
                         @3:@"Wrong password for user: {0}",
                         @4:@"User: {0} is banned",
                         @5:@"Zone: {0} is full.",
                         @6:@"User: {0} is already logged in Zone: {1}",
                         @7:@"The server is full",
                         @8:@"Zone: {0} is currently inactive",
                         @9:@"User name contains bad words. Name: {0}, Filtered: {1}",
                         @10:@"Guest users not allowed in Zone: {0}",
                         @11:@"IP Address: {0} is banned",
                         @12:@"A room with the same name already exists: {0}",
                         @13:@"Requested group is not available. Room: {0}, Group: {1}",
                         @14:@"Bad room name length. Min: {0}, Max: {1}, Your len: {2}",
                         @15:@"Room name contains bad words: {0}",
                         @16:@"Zone is full. Can't add any more rooms.",
                         @17:@"You have exceeded the number of rooms that you can create per session: {0}",
                         @18:@"Room creation failed, wrong parameter: {0}",
                         @19:@"User already joined in Room: {0}",
                         @20:@"The room is full: {0}",
                         @21:@"Wrong password for Room: {0}",
                         @22:@"Requested room doesn't exist",
                         @23:@"Room is locked: {0}",
                         @24:@"Group: {0} is already subscribed",
                         @25:@"Group: {0} does not exist",
                         @26:@"Group: {0} is not subscribed",
                         @27:@"Group: {0} does not exist",
                         @28:@"{0}",
                         @29:@"Room permission error. Room: {0} cannot be renamed",
                         @30:@"Room permission error: {0}, cannot change password state",
                         @31:@"Room permission error: {0}, cannot change capacity",
                         @32:@"SwitchUser error. No player slots available. Room: {0}",
                         @33:@"SwitchUser error. No spectator slots available. Room: {0}",
                         @34:@"SwitchUser error. Not a game Room: {0}",
                         @35:@"SwitchUser error. You are not joined in the Room: {0}",
                         @36:@"BuddyManager initialization error, could not load buddy list: {0}",
                         @37:@"BuddyManager error. Your buddy list is full. Size = {0}",
                         @38:@"BuddyManager error. Was not able to block buddy {0}, not online",
                         @39:@"BuddyManager error. You are attempting to set too many Buddy Variables, limit = {0}",
                         @40:@"Join Game Access Denied: {0} - User doesn't match access criteria.",
                         @41:@"QuickJoin failed: no matching Rooms were found",
                         @42:@"Your previous invitation reply was invalid or arrived too late."}];
}

+(NSString *)stringFormat:(NSString *)ss params:(NSArray *)params
{
	if (ss == nil)
    {
		return [NSString string];
	}
	
	
	if (params != nil)
    {
		for (int i = 0; i < [params count]; i++)
        {
			NSString *src = [NSString stringWithFormat:@"{%d}", i];
			ss = [ss stringByReplacingOccurrencesOfString:src withString:[params objectAtIndex:i]];
		}
	}
	
	return ss;
}

+(void)setErrorMessage:(NSNumber *)code message:(NSString *)message
{
    [_errorsByCode setObject:message forKey:code];
}

+(NSString *)getErrorMessage:(NSNumber *)code params:(NSArray *)params
{
    return [self stringFormat:[_errorsByCode objectForKey:code] params:params];
}



@end
