// CheckSwitch.h: interface for the CCheckSwitch class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include <array>

#include "cmnhdr.h"
#include "RunTask.h"
#include "Input.h"
#include "Output.h"
#include "commondef.h"
#include "DllDefines.h"

class CRunCtrl;

struct stMSG_SEND
{
    bool bOnSend;
    bool bOffSend;
};

class MCCTRDLLCLASS CCheckSwitch : public CRunTask
{
public:
    bool SetOuputState(int nOutput, bool bState);
    void DoorLock(bool bLock = true);
    bool IsEngineeringBypass();
    bool IsCurtainBypass();
    bool IsDoorBypass();
    bool IsDoorOpen();
    bool IsHardwareBypass();
    bool IsStopButtonActivated();
    void InitParameters();
    void BypassEngineering(bool bBypass = true);
    void BypassCurtain(bool bBypass = true);
    void BypassDoor(bool bBypass = true);
    void SetSystemOutput(int nOutput, COutput* copOutputPt);

    CCheckSwitch(CRunCtrl* pRunCtrl);
    virtual ~CCheckSwitch();

    UINT RunThread(void);

    void SetSwitch(int nSwitch, CInput* cipInputpt);

    //  Set door switch, curtain and engineering switch warn to not send before
    void ResetSwitchWarning();

    void SetGuiWindow(HWND hwnd);

    //
    void SetSafetySwitch(int nSwitch, bool bSafety);
    bool IsSafetySwitch(int nSwitch);

private:
    bool CheckSwitch(int nSwitchNo, CInput* cipSwitch, stMSG_SEND* pMsgSend, bool* pIsSendBefore);
    void GetMainApp();
    void CheckSwitch(int nSwitchNo, CInput* cipSwitch, stMSG_SEND* pMsgSend);

    std::array<bool, SWITCH_SYSTEM> m_bSafetySwitch;
    std::array<CInput*, SWITCH_SYSTEM> m_cipSwitch;

    std::array < stMSG_SEND, SWITCH_SYSTEM> m_stMsgSend;

    COutput* m_copSystemDoor;
    COutput* m_copCurtainSensorReset;

    HWND hwndMainApp;

    bool m_bBypassDoor;
    bool m_bBypassCurtain;
    bool m_bBypassEngineering;
    bool m_bHardwareBypass;
    bool m_bWrnOnEnggSwitch;

    // for ui-control decoupling
    CRunCtrl* m_pRunCtrl;
};
