#pragma once
#include <myapp/modbus/device.h>
#include <chrono>

namespace myapp::modbus::devices {

class MEg40 final : public device
{
public:
    explicit MEg40(std::string name, int slave_id, std::shared_ptr<connection>, std::shared_ptr<logging::logger>);
    void initialize() override;
    std::string handle_command_impl(std::string const&) override;
    void set_read_period(std::chrono::seconds::rep);

private:
	void phase_voltage_update(uint16_t L1, uint16_t L2, uint16_t L3);
	void line_voltage_update(uint16_t L1_L2, uint16_t L2_L3, uint16_t L3_L1);
	void phase_current_update(uint16_t L1, uint16_t L2, uint16_t L3);
	void real_power_update(uint16_t L1, uint16_t L2, uint16_t L3);
	void reactive_power_update(uint16_t L1, uint16_t L2, uint16_t L3);
	void power_factor_update(uint16_t L1, uint16_t L2, uint16_t L3);
	void EPP(uint16_t L1, uint16_t L2, uint16_t L3);
	void EPM(uint16_t L1, uint16_t L2, uint16_t L3);
	void EQPP(uint16_t L1, uint16_t L2, uint16_t L3);
	void EQPM(uint16_t L1, uint16_t L2, uint16_t L3);
	void EQMP(uint16_t L1, uint16_t L2, uint16_t L3);
	void EQMM(uint16_t L1, uint16_t L2, uint16_t L3);
	void voltage_range_update(uint16_t U_10);
	void power_range_update(uint16_t I);

private:
	poll::task_t register_poll_;
    std::chrono::seconds::rep read_period_;
    std::chrono::system_clock::time_point last_read_time_;
};

} /* namespace myapp::modbus::devices */
