<?php

class Atmail_Provider_Email_IMAP extends Atmail_Provider_Email_Abstract
{


	public $fieldMap = array(); //maps public field names to internal field names
	private $_myData = null;
	
	public function __construct( Array $configArray ) 
	{
		
		$this->_session = new Zend_Session_Namespace('defaultNamespace');
		$this->dbAdapter = Zend_Registry::get('dbAdapter');
		$this->username = $configArray['UserId'];
		$this->displayName = $configArray['DisplayName'];
		$this->Account = $this->_config['Account'];

		if( !parent::__construct($configArray) )
			return false;
		
	}
	
	public function getList( Array $args = array() )
	{
		
//Zend_Registry::get('log')->debug( "\n" . print_r($args, true) . "\n" . __METHOD__ . ' #' . __LINE__ . ": \$args \n");
		try 
		{

			if( !array_key_exists('data', $result) )
				$return['serviceData'] = $result;
			else
				$return['serviceData'] = $result['data'];
			$return['success'] = "true"; //Did the action complete without failure (server fails, network down etc.)
			$return['result'] = "true"; //Did the executing the action result in a success or fail for the commend (e.g. delete, or add)
			$return['noteEnglish'] = "Fetched remote data successfully"; //used for english display and translation
			$return['noteCode'] = "200"; //used for programatic success and result handling
			$return['lastUpdated'] = time();
			$return['serviceType'] = "SocialNetwork";
			$return['serviceName'] = "Facebook";
			$return['myId'] = $this->username;
			$return['myDisplayName'] = $this->displayName;
			$return['folder'] = $this->mapToPublic($args['folder']);
			
		} 
		catch( Exception $e) 
		{
			
			$return['success'] = "true"; //Did the action complete without failure (server fails, network down etc.)
			$return['result'] = "false"; //Did the executing the action result in a success or fail for the commend (e.g. delete, or add)
			$return['noteEnglish'] = "Failed fetching remote data: " . $e->getMessage(); //used for english display and translation
			$return['noteCode'] = "404"; //used for programatic success and result handling
			$return['lastUpdated'] = time();
			$return['serviceType'] = "SocialNetwork";
			$return['serviceName'] = "Facebook";
			$return['myId'] = $this->username;
			$return['myDisplayName'] = $this->displayName;
			$return['folder'] = $this->mapToPublic($args['folder']);
			
		}
		//Zend_Registry::get('log')->debug( "\n" . print_r($return, true) . "\n" . __METHOD__ . ' #' . __LINE__ . ": \$return \n");
		
		return $return;
		
	}

	public function getSummary( Array $args = array( 'groupBy' => 'from', 'groupOrder' => 'ASC') )
	{
		
	}
	
	public function getThread( Array $args = array() )
	{

	}
	
	public function getStream( Array $args = array() )
	{
		
	}


	public function getInfo( Array $args = array() )
	{
		
	}
	
	
	public function deleteThread( Array $args )
	{

	}
	public function delete( Array $args )
	{
		

	}
	
	public function getMyName()
	{
		
		return $this->_myData['name'];
		
	}

	public function getMyId()
	{
		
		return $this->_myData['id'];
	
	}
	
	public function getMyProfileImageUrl()
	{
		
	}
	
	
	public function post( Array $args)
	{

		
	}
	
	public function get( Array $args )
	{

	}
	
	public function getProfileImage( Array $args )
	{
		


	}

	
	private function mapToInternal( $publicField )
	{
		
		if( array_key_exists($publicField, $this->fieldMap) )
			return $this->fieldMap[$publicField];
		else
			return $publicField;
		
	}

	private function mapToPublic( $internalField )
	{
		
		$result = array_search($internalField, $this->fieldMap);
		if( $result )
			return $result;
		else
			return $internalField;
		
	}

	

}