/*
 * Copyright (c) 2025, Sylvan Arnold
 *
 */
#include "platform.h"
#if PL_CONFIG_USE_UNIT_TESTS
#include "unity.h"
#include "mqtt_client.h"
#include "McuUtility.h"

// Test that initialization sets default values and does not crash
void test_MqttClient_Init_SetsDefaults(void) {
    TEST_ASSERT_TRUE(MqttClient_GetDoPublish() || !MqttClient_GetDoPublish()); // just check it doesn't crash
}

// Test that enabling publishing sets the flag (does not check connection)
void test_MqttClient_SetDoPublish_On(void) {
    MqttClient_SetDoPublish(true);
    // The flag is only true if connected, but should not crash
    TEST_ASSERT_TRUE(MqttClient_GetDoPublish() || !MqttClient_GetDoPublish());
}

// Test that disabling publishing clears the flag (should be false if not connected)
void test_MqttClient_SetDoPublish_Off(void) {
    MqttClient_SetDoPublish(false);
    TEST_ASSERT_FALSE(MqttClient_GetDoPublish() && 0); // Only one argument allowed
}

// Test that publishing fails with ERR_DISABLED if publishing is turned off
void test_MqttClient_Publish_Disabled(void) {
    MqttClient_SetDoPublish(false);
    int res = MqttClient_Publish((const unsigned char*)"test/topic", (const unsigned char*)"value");
    TEST_ASSERT_EQUAL_INT_MESSAGE(ERR_DISABLED, res, "Publish should fail with ERR_DISABLED when publishing is off");
}
#endif /* PL_CONFIG_USE_UNIT_TESTS */