#ifndef MIDAS_DRIVERS_EPICS_EPICS_TOOL_H
#define MIDAS_DRIVERS_EPICS_EPICS_TOOL_H

#include "epics_ca.h"

#include <cstdint>
#include <string>

namespace epics_tool {

const double kDefaultTimeout = 1.0;

struct ScalarValue {
   char string_value[40]{};
   int16_t short_value = 0;
   float float_value = 0;
   uint16_t enum_value = 0;
   uint8_t char_value = 0;
   int32_t long_value = 0;
   double double_value = 0;

   void *data(chtype type);
   const void *data(chtype type) const;
};

bool parse_double(const char *text, double &value);
bool parse_priority(const char *text, capri &priority);
bool parse_type(const char *text, chtype &type);
bool parse_value(chtype type, const std::string &text, ScalarValue &value,
                 std::string &error);
std::string format_value(chtype type, const ScalarValue &value);
double timeout_from_environment();
const char *type_name(chtype type);
void print_ca_error(const char *operation, const char *pv, int status);

} // namespace epics_tool

#endif
