/*
{{copyright}} 
*/

/*
{{version}} 
*/

/*
{{license}} 
*/

#pragma once

#include "../defs.h"

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

namespace sdi_uToolBox::comm
{
//--------------------------------------------------------------
class ICommDevice
{
  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>;

  static constexpr auto INFINITE_DURATION = Timeout(-1);

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

  virtual ReturnType write(WriteBuf buf, Timeout timeout = INFINITE_DURATION) = 0;     // Write data to device
  virtual ReturnType read(ReadBuf buf, Timeout timeout = INFINITE_DURATION)   = 0;     // Read data from device
};
//--------------------------------------------------------------
}     // namespace sdi_uToolBox::comm