#pragma once

#include <Arduino.h>

#include "config.h"
#include "data_model.h"
#include "wifi_manager.h"

struct ReceiverSharedState {
  SenderStatus sender_statuses[NUM_SENDERS];
  FaultCounters sender_faults_remote[NUM_SENDERS];
  FaultCounters sender_faults_remote_published[NUM_SENDERS];
  FaultType sender_last_error_remote[NUM_SENDERS];
  FaultType sender_last_error_remote_published[NUM_SENDERS];
  uint32_t sender_last_error_remote_utc[NUM_SENDERS];
  uint32_t sender_last_error_remote_ms[NUM_SENDERS];
  bool sender_discovery_sent[NUM_SENDERS];
  uint16_t last_batch_id_rx[NUM_SENDERS];

  FaultCounters receiver_faults;
  FaultCounters receiver_faults_published;
  FaultType receiver_last_error;
  FaultType receiver_last_error_published;
  uint32_t receiver_last_error_utc;
  uint32_t receiver_last_error_ms;
  bool receiver_discovery_sent;
  bool ap_mode;
  
  // WiFi configuration and reconnection tracking
  WifiMqttConfig wifi_config;
  uint32_t last_wifi_reconnect_attempt_ms;
  char ap_ssid[32];  // AP SSID for restoring AP mode if reconnection fails
  char ap_password[32];  // AP password for restoring AP mode
};

