/*
{{copyright}} 
*/

/*
{{version}} 
*/

/*
{{license}} 
*/

#pragma once

#include "ICommBus.h"

#include <chrono>
#include <expected>
#include <span>

namespace sdi_uToolBox::comm
{
//--------------------------------------------------------------
class UARTBus : public ICommBus
{
  public:
  using ReadBuf    = std::span<uint8_t>;
  using WriteBuf   = std::span<const uint8_t>;
  using Timeout    = std::chrono::milliseconds;
  using ReturnType = std::expected<size_t, ReturnStatus>;

  public:
  UARTBus()                           = default;     // Default constructor
  virtual ~UARTBus() override         = default;     // Default destructor
  UARTBus(const UARTBus &)            = delete;      // Copy constructor
  UARTBus(UARTBus &&)                 = delete;      // Move constructor
  UARTBus &operator=(const UARTBus &) = delete;      // Copy assignment operator
  UARTBus &operator=(UARTBus &&)      = delete;      // Move assignment operator

  virtual ReturnType write(WriteBuf buf, Timeout timeout) const = 0;        // Write data to UART device
  virtual ReturnType read(ReadBuf buf, Timeout timeout) const   = 0;        // Read data from UART device
  virtual ReturnType readUntilIdle(ReadBuf buf, Timeout timeout) const;     // Read data until IDLE event
};
//--------------------------------------------------------------
/*  Read data until IDLE event */
inline UARTBus::ReturnType UARTBus::readUntilIdle(ReadBuf buf, Timeout timeout) const
{
  return std::unexpected(ReturnStatus::IncompatibleBaseType);
}
//--------------------------------------------------------------
}     // namespace sdi_uToolBox::comm