
#ifndef VOICEBOX_H
#define VOICEBOX_H

#define TRUE  1
#define FALSE 0

#include <string>
#include <list>
#include <map>

class astVoiceMessage
{
 private:

  // read actual information from the path -- is everything recorded?
  // maybe, we need an additional agi script which tracks additional info
  // into a corresponding meta data file
  void Read();
  int EqualPosition( std::string s );
  void CreateTime( std::string v );
  void CreateCaller( std::string v );

  std::string m_path, m_folder, m_name;
  std::string m_caller;
  std::string m_time, m_date;
  std::string m_duration;
  std::string m_extension;
  
 public:
  astVoiceMessage( std::string path, std::string folder, std::string );

  std::string GetPath();

  // who called
  std::string GetCallerId();

  // when was the message received
  std::string GetTime();
  std::string GetDate();
  std::string GetDuration();

  // the number dialed
  std::string GetExtension();

  // obtain the file location for playback
  std::string GetSoundfile( std::string extension );

  // move message to some other folder
  void MoveTo( std::string folder );  
};
  
class astVoicebox
{
 private:
  std::string m_basepath, m_current, m_name;

  std::list<astVoiceMessage> m_messages;
  std::list<std::string> m_folders;

 public:
  static const int GM_NONE   = 0;
  static const int GM_CALLER = 1;
  static const int GM_DATE   = 2;

  // remember path and name internally
  astVoicebox( std::string path, std::string name );

  // return name attribute
  std::string GetName();

  // re-read messages in this voicebox
  void RefreshMessages();

  // obtain message objects
  std::list<astVoiceMessage> GetMessages();

  // get grouped messages
  std::map<std::string, std::list<astVoiceMessage> > GetMessageGroups( int groupmode );

  // obtain count
  int GetCount();

  // folder management
  std::string GetCurrentFolder();

  void SetCurrentFolder( std::string folder );

  std::list<std::string> GetFolders();

  void RefreshFolders();

  void PurgeMessages();

};

class astVoiceboxList
{
 private:
  std::string m_path, m_name;

  std::list<astVoicebox> m_boxes;

 public:
  // create a maintainer of voiceboxes for a certain path
  astVoiceboxList( std::string path );

  // return a list of voicebox objects
  // (iterate directories in paths, create voicebox instances and return list)
  std::list<astVoicebox> GetVoiceboxes();

  void RefreshVoiceboxes();
};

#endif
