#pragma once

#include <cstdint>

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

enum IncommingCommands_e : uint16_t {
    Qurey = 0x00,           // Qurey info
    SetMaintanance = 0x01,  // Set Maintanance mode
    SetPromoMode = 0x02,    // Enable PromoMode
    SetGamingMode = 0x03,   // Enable in Game mode
};

enum ServiceCommands_e {
    SerQuery = 0x10,
    Open = 0x11,
    Close = 0x12,
    Play1 = 0x13,
    Play2 = 0x14,
    Play3 = 0x15,
};

enum GameModeCommands_e {
    GameNextTryLocked = 0x21,  // Lock sword on next try
    GameNextTryRelease = 0x22  // Release sword on next try
};

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

enum GameModeResponses_e {
    SwordPullHappend = 0x11,  // Message if User tried to pull the sword
    SwordReleased = 0x12,     // Message that User pulled the sword
    SwordReturned = 0x13      // 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;
};