/**
    File        : Account.h
    Description : Encapsulates a single account
    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 ACCOUNT_H_INCLUDED
#define ACCOUNT_H_INCLUDED

#include <wx/splitter.h>
#include <wx/string.h>
#include <wx/msgdlg.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include <wx/button.h>
#include <wx/dataview.h>
#include <wx/file.h>
#include <wx/ffile.h>
#include <wx/sstream.h>
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <vector>
#include "Base.h"
#include "IPlugin.h"

#define RECORD_SEPERATOR       wxT("\t")
#define TRANSACTION_SEPERATOR  wxT("\n")

class CTransactionList : public wxDataViewListModel
{
    public:
    CTransactionList();
    ~CTransactionList();

    void GetViewer();
    void SetNumberOfCols(unsigned int n);
    void AddLine(wxArrayString& Line) { m_TransactionList.push_back(Line); }
    unsigned int GetNumberOfCols();
    unsigned int GetNumberOfRows();
    wxString GetColType(unsigned int col);
    void GetValue(wxVariant& variant, unsigned int col, unsigned int row);
    bool SetValue(wxVariant& variant, unsigned int col, unsigned int row);

    private:
    std::vector<wxArrayString>  m_TransactionList;
    unsigned int                m_NumColumns;
};

class CAccount : public wxSplitterWindow
{
    public:
    CAccount(wxWindow* pParent, IPluginHost* pHost, SAccountInfo& AccountInfo);
    ~CAccount();

    bool LoadTransactionsFromDisk();
    bool SaveTransactionsToDisk();
    const SAccountInfo GetAccountInfo() { return m_AccountInfo; }
    const wxString GetAccountName()     { return m_AccountInfo.AccountName; }

    private:
    void GetViewer();

    // id's
    enum
    {
        idAccountWindow = 300,
        idTopPanel,
        idBottomPanel,
        idBalanceCtrl,
        idHideReconciledCtrl,
        idNewTransactionBtn,
        idSearchTransactionBtn,
        idBalanceAccountBtn,
        idTransactionListCtrl,
    };

    // event handlers

    // child controls
    wxPanel*                   m_pTopPanel;
    wxPanel*                   m_pBottomPanel;
    wxDataViewCtrl*            m_pTransactionListCtrl;
    CTransactionList*          m_pTransactionListModel;
    wxTextCtrl*                m_pBalanceCtrl;
    wxCheckBox*                m_pHideReconciledCtrl;

    // private data
    wxWindow*                  m_pParent;
    IPluginHost*               m_pHost;
    CAccountTypePluginBase*    m_pViewer;
    wxString                   m_Filename;
    SAccountInfo               m_AccountInfo;
    bool                       m_HideReconciled;
    std::vector<STransaction>  m_TransactionList;
    ULONG                      m_LastTransactionNumber;
    ULONG                      m_LastTransferNumber;
};

#endif // ACCOUNT_H_INCLUDED
