#pragma once

#include <array>
#include <QString>

namespace softbus::hardware::drivers::serial::capabilities
{

struct SerialDefaults
{
    int         baudRate    = 9600;
    int         dataBits    = 8;
    const char* parity      = "none";
    int         stopBits    = 1;
    const char* flowControl = "none";
};

inline constexpr SerialDefaults kDefaults{};

inline constexpr std::array<int, 5> kBaudRates{9600, 19200, 38400, 57600, 115200};
inline constexpr std::array<int, 4> kDataBits{5, 6, 7, 8};
inline constexpr std::array<const char*, 3> kParity{"none", "even", "odd"};
inline constexpr std::array<int, 2> kStopBits{1, 2};
inline constexpr std::array<const char*, 3> kFlowControl{"none", "hardware", "software"};

inline bool isValidBaud(int v)
{
    for (int b : kBaudRates) {
        if (b == v) return true;
    }
    return false;
}

inline bool isValidDataBits(int v)
{
    for (int b : kDataBits) {
        if (b == v) return true;
    }
    return false;
}

inline bool isValidParity(const QString& s)
{
    for (const char* p : kParity) {
        if (s == QLatin1String(p)) return true;
    }
    return false;
}

inline bool isValidStopBits(int v)
{
    for (int b : kStopBits) {
        if (b == v) return true;
    }
    return false;
}

inline bool isValidFlowControl(const QString& s)
{
    for (const char* f : kFlowControl) {
        if (s == QLatin1String(f)) return true;
    }
    return false;
}

} // namespace softbus::hardware::drivers::serial::capabilities

