package com.guru.facebook.feed.base 
{
	import com.adobe.serialization.json.JSONEncoder;
	import com.guru.facebook.FacebookDataBridge;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class FeedBase
	{
		protected var mMessage_str:String;
		protected var mName_str:String;
		protected var mCaption_str:String;
		protected var mDescription_str:String;
		protected var mImage_str:String;
		protected var mProperties_obj:Object;
		
		protected var mNameHref_str:String;
		protected var mImageHref_str:String;
		
		public function FeedBase() 
		{
			//mMessage_str = "This is testing message";
			//mName_str = "This is tester name";
			//mCaption_str = "This is testing caption";
			//mDescription_str = "This is testing description";
			//mImage_str = "http://www.oceanempiregame.com/iframe/swf/image/face.jpg";
			//
			//this.addProperties("name", "content");
			//this.addProperties("rating", "5 stars");
			//this.addProperties("others", "google", "http://www.google.com");
		}
		
		public function getImage():String
		{
			return mImage_str;
		}
		
		public function getNameHref():String
		{
			return mNameHref_str;
		}
		
		public function getImageHref():String
		{
			return mImageHref_str;
		}
		
		public function getCaption():String
		{
			return mCaption_str;
		}
		
		public function getName():String
		{
			return mName_str;
		}
		
		public function getDescription():String
		{
			return mDescription_str;
		}
		
		public function getMessage():String
		{
			return mMessage_str;
		}
		
		public function hasAttachment():Boolean
		{
			return mProperties_obj != null;
		}
		
		public function getAttachment():Object
		{
			var attachment_obj:Object = new Object();
			attachment_obj["name"] = mName_str;
			attachment_obj["href"] = mNameHref_str;
			attachment_obj["caption"] = mCaption_str;
			attachment_obj["description"] = mDescription_str;
			if (mProperties_obj != null)
			{
				attachment_obj["properties"] = new Object();
				for (var i in mProperties_obj)
				{
					attachment_obj["properties"][i] = mProperties_obj[i];
				}
			}
			attachment_obj["media"] = new Array();
			var media_obj:Object = new Object();
			media_obj = new Object();
			media_obj["type"] = "image";
			media_obj["src"] = mImage_str;
			attachment_obj["href"] = mImageHref_str;
			attachment_obj["media"].push(media_obj);
			
			return attachment_obj;
		}
		
		public function getAttachmentInString():String
		{
			var jsonEncoder:JSONEncoder = new JSONEncoder(this.getAttachment());			
			var attachment_str:String = jsonEncoder.getString();
			return attachment_str;
		}
		
		public function addProperties(pName_str:String, pContent_str:String, pHref_str:String = null):void
		{
			if(mProperties_obj == null)
				mProperties_obj = new Object();
				
			if (pHref_str == null)
			{
				mProperties_obj[pName_str] = pContent_str;
			}
			else
			{
				mProperties_obj[pName_str] = {text:pContent_str, href:pHref_str};
			}
		}
	}

}