#pragma once

#include <ranges>
#include <sstream>
#include <string_view>

#include "stm32f401xe.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_uart.h"

namespace driver::usart {

constexpr const uint8_t TX_BUFSIZE{20};
constexpr const uint8_t TX_TIMEOUT_MS{200};

class Usart {
   public:
    explicit Usart(USART_TypeDef* usart, uint32_t baudRate, uint32_t wordLength, uint32_t stopBits,
                   uint32_t parity, uint32_t mode, uint32_t hwFlowCtl, uint32_t overSampling);
    ~Usart() = default;

    bool init();
    void deinit();
    void print(const std::string_view str);
    void println(const std::string_view str);

   private:
    UART_HandleTypeDef mHandle{};

    void tx(std::string_view range);
};
}  // namespace driver::usart