#ifndef MQTT_HANDLER_H
#define MQTT_HANDLER_H

#include <DHCP/dhcp.h>

#include "ch32v003fun.h"
#include "w5500.h"

// Options structure for client identification
typedef struct {
  char* clientid;
  char* username;
  char* password;
  int qos;
} ch32_mqtt_options_t;

typedef struct {
  Network network;
  MQTTClient client;
  ch32_mqtt_options_t opts;
  uint32_t last_reconnect;
  uint32_t last_yield;
  uint8_t is_connected;
  char base_topic[64];
} mqtt_state_t;

void mqtt_init(mqtt_state_t* state);
void mqtt_process(mqtt_state_t* state);
void message_arrived(MessageData* md);
void publish_value(MQTTClient* client, const char* device_name,
                   const char* property, uint16_t value);

#endif