#ifndef OverbyteIcsMailQuTst1H
#define OverbyteIcsMailQuTst1H

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.Dialogs.hpp>
#include <Vcl.Forms.hpp>

#include "OverbyteIcsWndControl.hpp"
#include "OverbyteIcsMailQueue.hpp"
#include "OverbyteIcsSslHttpOAuth.hpp"
#include "OverbyteIcsOAuthFormVclE.hpp"
#include "OverbyteIcsSslBase.hpp"
#include "OverbyteIcsSslUtils.hpp"
#include "OverbyteIcsTypes.hpp"

#include <memory>

class TDemoForm : public TForm
{
__published:
    TPageControl *PageControl1;
    TTabSheet *TabMessage;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    TLabel *Label14;
    TLabel *Label11;
    TLabel *Label7;
    TButton *doSend;
    TMemo *RecipList;
    TEdit *MailSubject;
    TEdit *MailFrom;
    TButton *doExit;
    TButton *doClear;
    TComboBox *MailPriority;
    TEdit *FileAttachment;
    TButton *doQueue;
    TEdit *MailCC;
    TButton *doShowQu;
    TBitBtn *SelectAttachment;
    TGroupBox *BoxEML;
    TLabel *Label15;
    TEdit *EmlFileName;
    TBitBtn *SelectEmlFile;
    TButton *doSendEmlHdr;
    TButton *doSendEmlRecip;
    TButton *doCheckEml;
    TTabSheet *TabServers;
    TGroupBox *SMTPServer1;
    TLabel *Label21;
    TLabel *LabelAuthUser;
    TLabel *LabelAuthPass;
    TLabel *Label24;
    TLabel *Label26;
    TLabel *Label65;
    TEdit *PrefEmailSmtp1;
    TRadioGroup *PrefEmailAuthType1;
    TComboBox *PrefEmailSecure1;
    TEdit *PrefEmailAuthUser1;
    TEdit *PrefEmailAuthPass1;
    TCheckBox *PrefEmailSslErr1;
    TComboBox *PrefEmailSecurity1;
    TEdit *PrefEmailPort1;
    TGroupBox *SMTPServer2;
    TLabel *Label54;
    TLabel *Label55;
    TLabel *Label56;
    TLabel *Label57;
    TLabel *Label28;
    TLabel *Label67;
    TEdit *PrefEmailSmtp2;
    TEdit *PrefEmailAuthUser2;
    TEdit *PrefEmailAuthPass2;
    TRadioGroup *PrefEmailAuthType2;
    TComboBox *PrefEmailSecure2;
    TCheckBox *PrefEmailSslErr2;
    TComboBox *PrefEmailSecurity2;
    TEdit *PrefEmailPort2;
    TTabSheet *TabSettings;
    TLabel *Label8;
    TLabel *Label9;
    TLabel *Label6;
    TLabel *Label10;
    TLabel *Label5;
    TLabel *Label12;
    TLabel *Label22;
    TRadioGroup *PrefSendMethod;
    TRadioGroup *PrefVerifyCertMode;
    TEdit *PrefDnsServer;
    TEdit *PrefHeloHost;
    TEdit *PrefMailQuFolder;
    TEdit *PrefAttemptsList;
    TCheckBox *PrefSslRevoke;
    TEdit *PrefCARootBundle;
    TEdit *PrefClientCertFile;
    TEdit *DirLogs;
    TGroupBox *OAuth2Settings;
    TLabel *Label44;
    TLabel *Label45;
    TLabel *Label47;
    TLabel *Label48;
    TLabel *Label51;
    TLabel *Label13;
    TEdit *PrefClientId;
    TEdit *PrefRefrToken;
    TEdit *PrefTokenAccnt;
    TComboBox *PrefRestType;
    TEdit *PrefClientSecret;
    TComboBox *PrefUserAuth;
    TCheckBox *PrefExtBrow;
    TRichEdit *MailLog;
    TPanel *PanelBottom;
    TLabel *LabelProg;
    TLabel *LabelCount;
    TLabel *LabelQueue;
    TMemo *MailBody;
    TStatusBar *Status;
    TTimer *TimerUpdates;
    TIcsMailQueue *IcsMailQueue1;
    TIcsRestEmail *IcsRestEmail1;
    TOAuthBrowser *OAuthBrowser1;
    TOpenDialog *OpenDialog;
    void __fastcall doSendClick(TObject *Sender);
    void __fastcall doExitClick(TObject *Sender);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall doClearClick(TObject *Sender);
    void __fastcall FormResize(TObject *Sender);
    void __fastcall doQueueClick(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
    void __fastcall doShowQuClick(TObject *Sender);
    void __fastcall TimerUpdatesTimer(TObject *Sender);
    void __fastcall IcsMailQueue1LogEvent(TMailLogLevel LogLevel, const String Info);
    void __fastcall IcsMailQueue1QuChangedEvent(TObject *Sender);
    void __fastcall PrefEmailSecure1Change(TObject *Sender);
    void __fastcall PrefEmailSecure2Change(TObject *Sender);
    void __fastcall PrefChange(TObject *Sender);
    void __fastcall IcsMailQueue1OATokenEvent(int ServNr, String &Token, String &TokAccount, TDateTime &TokExpireDT);
    void __fastcall IcsRestEmail1EmailNewToken(TObject *Sender);
    void __fastcall IcsRestEmail1EmailProg(TObject *Sender, TLogOption LogOption, const String Msg);
    void __fastcall IcsRestEmail1OAEmbed(TObject *Sender, const String URL, bool &Success);
    void __fastcall SelectAttachmentClick(TObject *Sender);
    void __fastcall SelectEmlFileClick(TObject *Sender);
    void __fastcall doSendEmlHdrClick(TObject *Sender);
    void __fastcall doCheckEmlClick(TObject *Sender);
    void __fastcall doSendEmlRecipClick(TObject *Sender);

private:
    String FBuffDiags;
    String FBuffInfos;
    bool FQuUpdateFlag;
    std::unique_ptr<TIcsBuffLogStream> FIcsBuffLogStream;
    void __fastcall MailLogAdd(const String &Info);
    void __fastcall MailDiagAdd(const String &Info);
    void __fastcall StartQueueMail();
    void __fastcall StopQueueMail();
    void __fastcall OpenLogFile();
    bool __fastcall PrepareToQueue();

public:
    __fastcall TDemoForm(TComponent *Owner);
    __fastcall ~TDemoForm();
};

extern PACKAGE TDemoForm *DemoForm;
extern String IniFileName;
extern bool DiagWinFlag;
extern bool ViewQuWinFlag;

#endif
