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

@implementation SFSRoomVariable

@dynamic isPersistent;
@dynamic isPrivate;

+(id <RoomVariable>)fromSFSArray:(id <ISFSArray>)sfsa
{
	
	id <RoomVariable> roomVariable = [[SFSRoomVariable alloc] initWithName:[sfsa getUtfString:0] value:[sfsa getElementAt:2] type:[sfsa getByte:1]];
	
	[roomVariable setIsPrivate:[sfsa getBool:3]];
	
	return roomVariable;
}

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

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

+(id)variableWithName:(NSString *)name value:(id)value isPrivate:(BOOL)priv isPersistent:(BOOL) pers
{
    SFSRoomVariable* rVar = [[SFSRoomVariable alloc] initWithName:name value:value type:-1];
    [rVar setIsPrivate:priv];
    [rVar setIsPersistent:pers];
    
    return rVar;
}

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

-(BOOL)isPrivate {
	return _isPrivate;
}

-(BOOL)isPersistent {
	return _isPersistent;
}

-(void)setIsPrivate:(BOOL)value {
	_isPrivate = value;
}

-(void)setIsPersistent:(BOOL)value {
	_isPersistent = value;
}

-(NSString *)description {
	NSMutableString *str = [NSMutableString stringWithString:@"[RVar: "];
	
	[str appendString:[NSString stringWithFormat:@"%@, type: %@, value: %@, isPriv: %@]", _name, _type, _value, _isPrivate ? @"YES" : @"NO"]];
	
	return str;
}

@end
