/*
 * SPDX-FileCopyrightText: 2024 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#include "callback_mock_helpers.h"
#include "common.h"

#include <tango/client/AttrReadEvent.h>
#include <tango/client/AttrWrittenEvent.h>
#include <tango/client/CmdDoneEvent.h>

#include <catch2/catch_test_macros.hpp>

namespace TangoTest
{

AttrReadEventCopyable::AttrReadEventCopyable(Tango::AttrReadEvent *event)
{
    REQUIRE(event != nullptr);

    device = event->device;
    attr_names = event->attr_names;
    if(event->argout)
    {
        argout = *(event->argout);
        delete event->argout;
        event->argout = nullptr;
    }
    err = event->err;
    errors = event->errors;
}

AttrWrittenEventCopyable::AttrWrittenEventCopyable(Tango::AttrWrittenEvent *event)
{
    REQUIRE(event != nullptr);

    device = event->device;
    attr_names = event->attr_names;
    err = event->err;
    errors = event->errors;
}

CmdDoneEventCopyable::CmdDoneEventCopyable(Tango::CmdDoneEvent *event)
{
    REQUIRE(event != nullptr);

    device = event->device;
    cmd_name = event->cmd_name;
    argout = event->argout;
    err = event->err;
    errors = event->errors;
}

template <>
TangoTest::AttrReadEventCopyable construct_default()
{
    std::vector<std::string> att_names;
    Tango::DevErrorList errors;
    Tango::AttrReadEvent event(nullptr, att_names, nullptr, errors);
    TangoTest::AttrReadEventCopyable var(&event);

    return var;
}

template <>
TangoTest::AttrWrittenEventCopyable construct_default()
{
    std::vector<std::string> att_names;
    Tango::NamedDevFailedList errors;
    Tango::AttrWrittenEvent event(nullptr, att_names, errors);
    TangoTest::AttrWrittenEventCopyable var(&event);

    return var;
}

template <>
TangoTest::CmdDoneEventCopyable construct_default()
{
    std::string cmd_name;
    Tango::DevErrorList errors;
    Tango::DeviceData argout;
    Tango::CmdDoneEvent event(nullptr, cmd_name, argout, errors);
    TangoTest::CmdDoneEventCopyable var(&event);

    return var;
}

} // namespace TangoTest
