// ITransport 인터페이스 (🔥 최종본)
// itransport.hpp


#pragma once

#include <cstdint>
#include <vector>
#include "transport_error.hpp"

// transport 상태관리
enum class TransportState {
    Disconnected,
    Connecting,
    Connected,
    Reconnecting,
    Fault,
};
class ITransport {
public:
    virtual ~ITransport() = default;

    // connection
    virtual bool connect(const char* host, std::uint16_t port) = 0;
    virtual void disconnect() = 0;
    virtual bool is_connected() const = 0;

    // state & error handling
    virtual TransportState state() const = 0;
    virtual TransportError last_error() const = 0;

    // io policy
    virtual bool can_io() const = 0;   // ⭐ 추가 (권장)
    
    // watchdog / reconnect / state machine
    virtual void poll() = 0;
    virtual void reset() = 0;   // ⭐ 추가

    // register access
    virtual bool read_registers(std::uint16_t addr,
                                std::uint16_t count,
                                std::vector<std::uint16_t>& out) = 0;

    virtual bool write_registers(std::uint16_t addr,
                                 const std::vector<std::uint16_t>& values) = 0;

};