//
//  SFSUserVariable.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 "SFSUserVariable.h"
#import "VariableType.h"
#import "SFSArray.h"
#import "SFSObject.h"
#import "SFSException.h"

@implementation SFSUserVariable
{
    @protected
    BOOL _isPrivate;
}


+(id)variableWithName:(NSString *)name value:(id)value type:(NSInteger)type
{
    SFSUserVariable* uVar = [[SFSUserVariable alloc] initWithName:name value:value type:type];
    return uVar;
}

+(id)variableWithName:(NSString *)name value:(id)value
{
    SFSUserVariable* uVar = [[SFSUserVariable alloc] initWithName:name value:value type:-1];
    return uVar;
}

+(id <UserVariable>)fromSFSArray:(id <ISFSArray>)sfsa
{
	
	id <UserVariable> variable = [[SFSUserVariable alloc] initWithName:[sfsa getUtfString:0] value:[sfsa getElementAt:2] type:[sfsa getByte:1]];
    
    // Since 2.12.0 we're getting a new element at position #3 (isPrivate flag)
    if ([sfsa size] > 3)
        [variable setPrivate:[sfsa getBool:3]];
	
	return variable;
}

+(id <UserVariable>) privateVariableWithName:(NSString *)name value:(id)value
{
    SFSUserVariable* uVar = [SFSUserVariable variableWithName:name value:value];
    [uVar setPrivate:YES];
    
    return uVar;
}

- (BOOL) isPrivate
{
    return _isPrivate;
}

- (void) setPrivate:(BOOL)priv
{
    _isPrivate = priv;
}

-(id<ISFSArray>)toSFSArray
{
    id<ISFSArray> sfsa = [super toSFSArray];
    [sfsa addBool: _isPrivate];
    
    return sfsa;
}


@end
