#pragma once

#include <cstdint>

static constexpr uint16_t UndefCmd = 0xFFFF;
enum ConMode_e {
    ModeMqtt,
    ModeLoRa
};

enum IncommingCommands_e : uint16_t {
    Qurey,           // Qurey info
    SetMaintanance,  // Set Maintanance mode
    SetPromoMode,    // Enable PromoMode
    SetGamingMode,   // Enable in Game mode
};

enum ServiceCommands_e {
    Open,
    Close,
    Play1,
    Play2,
    Play3,
};

enum GameModeCommands_e {
    GameNextTryLocked,    // Lock sword on next try
    GameNextTryRelease  // Release sword on next try
};

enum OutgoingCommands_e {
    Status,      // Send Status
    Response,    // Confirm last command
    Error,       // Send error status
    PullHappend  // Message if User tried to pull the sword
};

enum GameModeResponses_e {
    SwordPullHappend,  // Message if User tried to pull the sword
    SwordReleased,     // Message that User pulled the sword
    SwordReturned      // Message that User returned the sword
};

struct StatusFrame {
    uint8_t cmd{OutgoingCommands_e::Status};
    uint8_t version[4];
    uint8_t mode;
    uint8_t healt;
    uint8_t sensors;
};

struct ResponseFrame {
    uint8_t cmd{OutgoingCommands_e::Response};
    uint8_t resCmd;
    uint8_t status;
};

struct RxMsg {
    RxMsg(uint16_t m)
        : code(m) {};
    uint16_t code;
};

struct TxMsg {
    TxMsg(uint32_t m)
        : cmd(m) {};
    uint8_t cmd;
};
struct ResponseTxMsg : public TxMsg {
    ResponseTxMsg(uint16_t cmd, uint8_t stat)
        : TxMsg(OutgoingCommands_e::Response) {};
    uint16_t resCmd;
    uint8_t status;
};
struct StatusTxMsg : public TxMsg {
    StatusTxMsg(uint8_t mode, uint8_t swEnd, uint8_t swBeg, uint8_t swPull, uint8_t out)
        : TxMsg(OutgoingCommands_e::Status),
          _mode(mode),
          _inSwEnd(swEnd),
          _inSwBeg(swBeg),
          _inSwPull(swPull),
          _out(out) {
    }
    uint8_t _mode;
    bool _inSwEnd;
    bool _inSwBeg;
    bool _inSwPull;
    bool _out;
};