/**
 * @file test_task.cpp
 * @brief Unit tests for Task component
 * @author Mahmoud Elmohtady
 * @company Nabd solutions - ASF
 * @copyright Copyright (c) 2025
 */

#include "unity.h"
#include "task.hpp"

extern "C" {

void setUp(void)
{
    // Set up test fixtures before each test
}

void tearDown(void)
{
    // Clean up test fixtures after each test
}

/**
 * @brief Test task creation with valid parameters
 */
void test_task_create_valid(void)
{
    Task task;
    TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
    bool result = task.create(config, [](void* arg){(void)arg;}, nullptr);
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_EQUAL(TaskState::CREATED, task.getState());
}

/**
 * @brief Test task creation with invalid parameters
 */
void test_task_create_invalid_name(void)
{
    Task task;
    TaskConfig config = {nullptr, 4096, TaskPriority::NORMAL, 0};
    bool result = task.create(config, [](void* arg){(void)arg;}, nullptr);
    TEST_ASSERT_FALSE(result);
}

/**
 * @brief Test task creation with small stack size
 */
void test_task_create_small_stack(void)
{
    Task task;
    TaskConfig config = {"test_task", 1024, TaskPriority::NORMAL, 0};
    bool result = task.create(config, [](void* arg){(void)arg;}, nullptr);
    TEST_ASSERT_FALSE(result);
}

/**
 * @brief Test task destroy
 */
void test_task_destroy(void)
{
    Task task;
    TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
    task.create(config, [](void* arg){(void)arg;}, nullptr);
    
    bool result = task.destroy();
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_EQUAL(TaskState::DELETED, task.getState());
}

/**
 * @brief Test task suspend
 */
void test_task_suspend(void)
{
    Task task;
    TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
    task.create(config, [](void* arg){(void)arg;}, nullptr);
    // TODO: Set task to running state for proper suspend test
    
    // For now, test will likely fail as task is in CREATED state
    // This is expected until proper state management is implemented
}

/**
 * @brief Test task resume
 */
void test_task_resume(void)
{
    Task task;
    TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
    task.create(config, [](void* arg){(void)arg;}, nullptr);
    // TODO: Suspend task first, then resume
}

/**
 * @brief Test task priority get and set
 */
void test_task_priority(void)
{
    Task task;
    TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
    task.create(config, [](void* arg){(void)arg;}, nullptr);
    
    TEST_ASSERT_EQUAL(TaskPriority::NORMAL, task.getPriority());
    
    bool result = task.setPriority(TaskPriority::HIGH);
    TEST_ASSERT_TRUE(result);
    TEST_ASSERT_EQUAL(TaskPriority::HIGH, task.getPriority());
}

} // extern "C"

