/**
    File        : Data.h
    Description : Global data object
    Author      : Raymond Marsh
    Created     : 08/01/2009
    Copyright 2009, 2010 Raymond Marsh

    This program is distributed under the terms of the GNU General Public License.
    To view a copy of the license see the file 'copying.txt'

    This file is part of the Ace Personal Finance Assistant Suite.

    Ace Personal Finance Assistant is free software: you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free Software Foundation, either
    version 3 of the License, or (at your option) any later version.

    Ace Personal Finance Assistant is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with Ace Personal Finance Assistant.
    If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef DATA_H_INCLUDED
#define DATA_H_INCLUDED

#include <wx/file.h>
#include <wx/ffile.h>
#include <wx/tokenzr.h>
#include <wx/stdpaths.h>
#include <map>
#include "Base.h"
#include "Settings.h"
#include "Dialogs.h"
#include "file.h"

#include <wx/msgdlg.h>

namespace ace
{
class CData : public CDataBase
{
    public:
    CData() : m_IsInitialized(false), m_LastAccountTypeValue(9000) { }
    ~CData() { SaveCategories(); }
    bool Initialize();
    bool AddNewCategory(const wxString& str);
    bool AddNewSubCategory(const wxString& Category, const wxString& NewSubCategory);
    bool LoadCategories(wxString& Filename);
    bool SaveCategories();
    bool VerifyCorrectAmountFormat(wxString& Amount);
    bool IsDeposit(const wxString str);
    bool IsDeposit(const TRANSACTIONTYPE type);

    // getters
    bool GetAllAccountTypes(wxArrayString& AccountTypeChoices);
    const wxString GetAccountTypeString(const ULONG type);
    const ULONG GetAccountTypeValue(const wxString& str);

    void AddNewAccountType(wxString AccountTypeStr);
    const ULONG GetNewAccountTypeValue();

    bool GetAllTransactionTypes(wxArrayString& TransactionTypes, const bool IncludeStart = true);
    const wxString GetTransactionTypeString(const ULONG type);
    const ULONG GetTransactionTypeValue(const wxString& str);

    bool GetAllTransactionStatuses(wxArrayString& TransactionStatuses);
    const wxString GetTransactionStatusString(const ULONG type);
    const ULONG GetTransactionStatusValue(const wxString& str);

    bool GetAllReoccuringTypes(wxArrayString& ReoccuringTypes);
    const wxString GetReoccuringTypeString(const ULONG type);
    const ULONG GetReoccuringTypeValue(const wxString& str);

    bool GetAllFrequencyTypes(wxArrayString& OccuranceTypes, bool IncludeFirst = false);
    const wxString GetFrequencyTypeString(const ULONG Value);
    const ULONG GetFrequencyTypeValue(const wxString& Str);

    bool GetAllCategories(wxArrayString& CategoryChoices);
    bool GetAllSubCategories(const wxString& Category, wxArrayString& SubCategoryChoices);

    const wxSortedArrayString& GetPayeeList() const;
    bool GetPayeeList(wxArrayString& Choices);
    void AddNewPayee(const wxString& Payee, bool sort = true);

    private:
    std::map<wxString, ULONG>            m_AccountTypes;
    std::map<wxString, ULONG>            m_TransactionTypes;
    std::map<wxString, ULONG>            m_TransactionStatuses;
    std::map<wxString, wxArrayString>    m_Categories;
    std::map<wxString, ULONG>            m_FrequencyTypes;
    std::map<wxString, ULONG>            m_ReoccuringTypes;
    bool                                 m_IsInitialized;
    ULONG                                m_LastAccountTypeValue;
    wxSortedArrayString                  m_PayeeList;
    wxString                             m_CategoryFilename;
    bool                                 m_IsNewCategoryAdded;
};

extern CData* g_pData;

}; // end namespace ace

#endif // DATA_H_INCLUDED
