// EquipState.h: interface for the CEquipState class.
//
//////////////////////////////////////////////////////////////////////
#pragma once

#include <array>
#include <string>

#include "TimeEquipSubState.h"

class CEquipState
{
public:
    //  default constructor
    explicit CEquipState(int iNoOfEquipState);

    //  default Destructor
    virtual ~CEquipState();

    //  read all equipment SubState time span from file
    virtual void ReadTimeSpanFromFile();

    //  get equipment substate time
    virtual LONGLONG GetEquipSubStateTime(int iEvt);

    //  save equipment substate time that is clocking to file
    virtual void SaveTimeInfo();

    //  check is equipment Substate timer started
    virtual bool IsTimerStarted(int iEvt);

    enum
    {
        NON_SCHEDULE_TIME,
        ENGINEERING_TIME,
        PRODUCTIVE_TIME,
        STANDBY_TIME,
        UNSCHEDULED_DOWNTIME,
        SCHEDULED_DOWNTIME,
        MANUFACTURING_TIME,
        UPTIME,
        DOWNTIME,
        OPERATIONS_TIME,
        TOTAL_TIME,
        MAX_EQUIP_STATE,

        MAX_EQUIP_SUB_STATE = 6,
    };

    enum
    {
        UNWORK_SHIFT_DAYS_EVT,
        INSTALLATION_MODIFICATION_REBULID_UPGRADE_EVT,
        OFFLINE_TRAINING_EVT,
        SHUTDOWN_START_UP_EVT,
        PROCESS_EXPERIMENTS_EVT,
        EQUIP_EXPERIMENTS_EVT,
        SOFTWARE_QUALIFICATION_EVT,
        REGULAR_PRODUCTION_EVT,
        WORK_FOR_3RD_PARTY_EVT,
        REWORK_EVT,
        ENGINEERING_RUNS_EVT,
        NO_OPERATOR_EVT,
        NO_PRODUCT_EVT,
        NO_SUPPORT_TOOL_EVT,
        STOP_MACHINE_EVT,
        UNSCHEDULED_MAINT_DELAY_EVT,
        JAM_EVT,
        UNSCHEDULED_CHANGE_OF_CONSUMABLES_CHEMICALS_EVT,
        OUT_OF_SPEC_INPUT_EVT,
        UNSCHEDULED_FACILITIES_RELATED_EVT,
        SCHEDULED_MAINT_DELAY_EVT,
        PRODUCTION_TEST_EVT,
        PREVENTIVE_MAINT_EVT,
        SCHEDULED_CHANGE_OF_CONSUMABLES_CHEMICALS_EVT,
        SETUP_EVT,
        SCHEDULED_FACILITIES_RELATED_EVT,
        MAX_EQUIPMENT_SUBSTATE,
        LOT_CLOSED_EVT,
        LOT_OPEN_EVT,
        STOP_ALL_TIMER_EVT,
        RESET_ALL_TIMER_EVT,
        START_ALL_TIMER_EVT, // Possible to start all timer? need to have this event?
    };

    static std::array<std::string, MAX_EQUIPMENT_SUBSTATE> m_csKeyName;  // key name of debug info file
    static std::array<const char*, MAX_EQUIP_STATE>        m_sSectionName; // Section name of debug info file

protected:
    //  set equipment state time
    virtual void SetEquipTime(int iEquipSubStateNo, int iState);

    //  get total Equipment time
    virtual LONGLONG GetTotalEquipTime();

    //  set all equipment State
    virtual void SetAllEquipState(int iEvt, int iState);

    //  write all equipment SubState time span To File
    virtual void WriteAllEquipSubStateTimeSpanToFile(const std::string& csFileName    = RUNTIME_INI,
        const std::string&                                              csSectionName = "SEMIE10");

    //  write individual equipment SubState time span to file
    virtual void WriteTimeSpanToFile(int iEquipSubStateNo, const std::string& csFileName = RUNTIME_INI,
        const std::string& csSectionName = "SEMIE10");

    //  read individual equipment SubState time span from file
    virtual void ReadTimeSpanFromFile(int iEquipSubStateNo, const std::string& csFileName = RUNTIME_INI,
        const std::string& csSectionName = "SEMIE10");

    //  Check open lot event
    virtual void CheckOpenLotEvt(int iEvt);

    //  Check close lot event
    virtual void CheckCloseLotEvt(int iEvt);

    //  set equipment SubState time
    virtual void SetEquipSubStateTime(int iEquipSubStateNo, LONGLONG lTimeSpan);

    //  add equipment SubState time
    virtual void AddEquipSubStateTime(int iEquipSubStateNo, LONGLONG lTimeSpan);

    std::array<int, MAX_EQUIP_SUB_STATE> m_iEvt;

    std::array<CTimeEquipSubState, MAX_EQUIP_SUB_STATE> m_ctesEquipSubState;

private:
    // prevent accidental copy
    CEquipState(const CEquipState& rhs);

    int m_iNoOfEquipSubState; // num of equipment state
                              //  int m_iEquipSubStateNo; // equipment state number

    //  Equipment substate time has been written to file before
    bool m_bOpenLot;

    //  to init section name and keyname
    static void iniSectionAndKeyName();
};
