/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#ifndef TANGO_CLIENT_DEVICEATTRIBUTEHISTORY_H
#define TANGO_CLIENT_DEVICEATTRIBUTEHISTORY_H

#include <tango/client/DeviceAttribute.h>

namespace Tango
{
/**
 * Fundamental type for receiving data from device attribute polling buffers
 *
 * This is the fundamental type for receiving data from device attribute polling buffers. This class inherits
 * from the Tango::DeviceAttribute class. One instance of this class is created for each attribute result history.
 * Within this class, you find the attribute result data or the exception parameters and a flag indicating if the
 * attribute has failed when it was invoked by the device server polling thread. For history calls, it is not
 * possible to returns attribute error as exception. See chapter on Advanced Features in the
 * <a href=http://www.esrf.eu/computing/cs/tango/tango_doc/kernel_doc/ds_prog/index.html target=new>Tango book</a> for
 * all details regarding device polling.
 *
 *
 * @headerfile tango.h
 * @ingroup Client
 */
class DeviceAttributeHistory : public DeviceAttribute
{
  public:
    ///@privatesection
    //
    // constructor methods
    //

    DeviceAttributeHistory();
    DeviceAttributeHistory(int, DevAttrHistoryList_var &);
    DeviceAttributeHistory(int, DevAttrHistoryList_3_var &);
    DeviceAttributeHistory(const DeviceAttributeHistory &);
    DeviceAttributeHistory &operator=(const DeviceAttributeHistory &);
    DeviceAttributeHistory(DeviceAttributeHistory &&);
    DeviceAttributeHistory &operator=(DeviceAttributeHistory &&);

    ~DeviceAttributeHistory() override;

    ///@publicsection
    /**
     * Check if the record was a failure
     *
     * Returns a boolean set to true if the record in the polling buffer was a failure
     *
     * @return A boolean set to true if the record was a failure
     */
    bool has_failed()
    {
        return fail;
    }

    /**
     * Print a DeviceAttributeHistory instance
     *
     * Is an utility function to easily print the contents of a DeviceAttributeHistory object. This function knows
     * all types which could be inserted in a DeviceAttributeHistory object and print them accordingly. It also
     * in case the attribute returned an error.
     * @code
     * DeviceProxy *dev = new DeviceProxy(“...”);
     * int hist_depth = 4;
     * std::vector<DeviceAttributeHistory> *hist;

     * hist = dev->attribute_history(“MyAttribute”,hist_depth);

     * for (int i = 0;i < hist_depth;i++)
     * {
     *    std::cout << (*hist)[i] << std::endl;
     * }
     * delete hist;
     * @endcode
     *
     * @param [in] str The printing stream
     * @param [in] dah The instance to be printed
     */
    friend std::ostream &operator<<(std::ostream &str, const DeviceAttributeHistory &dah);

    ///@privatesection
    // Three following methods for compatibility with older release

    bool failed()
    {
        return fail;
    }

    void failed(bool val)
    {
        fail = val;
    }

    TimeVal &date()
    {
        return time;
    }

    //    const DevErrorList &errors() {return err;}

  protected:
    ///@privatesection
    bool fail;
    char compatibility_padding[16];

  private:
    class DeviceAttributeHistoryExt
    {
      public:
        DeviceAttributeHistoryExt() { }
    };

    std::unique_ptr<DeviceAttributeHistoryExt> ext_hist;
};
} // namespace Tango
#endif
